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()

INSTALLED VERSIONS ------------------ commit: None python: 3.5.2.final.0 python-bits: 64 OS: Linux OS-release: 4.4.0-66-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_GB.UTF-8 pandas: 0.19.2 nose: 1.3.7 pip: 8.1.2 setuptools: 27.2.0 Cython: 0.24.1 numpy: 1.11.3 scipy: 0.18.1 statsmodels: 0.6.1 xarray: None IPython: 5.1.0 sphinx: 1.4.6 patsy: 0.4.1 dateutil: 2.5.3 pytz: 2016.6.1 blosc: None bottleneck: 1.1.0 tables: 3.2.3.1 numexpr: 2.6.1 matplotlib: 1.5.3 openpyxl: 2.3.2 xlrd: 1.0.0 xlwt: 1.1.2 xlsxwriter: 0.9.3 lxml: 3.6.4 bs4: 4.5.1 html5lib: None httplib2: None apiclient: None sqlalchemy: 1.0.13 pymysql: 0.7.9.None psycopg2: None jinja2: 2.8 boto: 2.42.0 pandas_datareader: None

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).