Code Sample
In [49]: min(pd.Series([pd.np.nan, 1, 2, pd.np.nan]))
Out[49]: nan
In [50]: min(pd.Series([1, 2, pd.np.nan]))
Out[50]: 1.0
Problem description
Inconsistent handling of nans depending on whether the series starts with a nan.
Expected Output
Either 1.0 in both cases or nan in both cases
Output of pd.show_versions()
Comment From: robinsonjj
not sure whether this is possible to fix since it's using the inbuilt python min - it works fine using .min()
Comment From: jorisvandenbossche
Indeed, as you say, your example is using the built-in min
, which you should not do with arrays/Series (for performance reasons, and for eg such inconsistencies with missing values). I don't think this can be solved, as I suppose min
is implemented by comparing the values, and comparing to NaN always returns False.
BTW, just using builtin, this also 'fails':
In [21]: min(float('nan'), 1, 2)
Out[21]: nan
In [22]: min(1, float('nan'), 2)
Out[22]: 1
Comment From: jreback
this is a consequence of python not allowing overloading of these built-ins in context. not a pandas issue per-se (though certainly a user confusion issue).