The max()
and min()
functions are both returning np.nan
if I have an array that starts with np.nan
Here is where it works as expected:
>>> column_data = np.array([111, np.nan, 112, np.nan, 115, np.nan, 116, np.nan, 117, np.nan, 118, np.nan, 119])
>>> print(max(column_data))
119.0
>>> print(min(column_data))
111.0
Now I add an np.nan
at the beginning of the array, and it screwed up
>>> column_data = np.array([np.nan, 111, np.nan, 112, np.nan, 115, np.nan, 116, np.nan, 117, np.nan, 118, np.nan, 119])
>>> print(max(column_data))
nan
>>> print(min(column_data))
nan
I've tried filtering out the nan elements, but still the same:
>>> print(max(i for i in column_data if i is not np.nan))
nan
>>> print(min(i for i in column_data if i is not np.nan))
nan
What happened here and how do I fix this?