Closed
Description
Ran into this while looking at #27801.
Both numpy and pandas raise an error for empty arrays/Series in argmin
and argmax
:
>>> pd.Series([], dtype=float).argmin()
...
ValueError: attempt to get argmin of an empty sequence
>>> np.array([], dtype=float).argmin()
...
ValueError: attempt to get argmin of an empty sequence
However, when having all NaN data, we see a different behaviour:
>>> pd.Series([np.nan, np.nan], dtype=float).argmin()
-1
>>> np.array([np.nan, np.nan], dtype=float).argmin()
0
Does somebody have an explanation of why this would return -1 ?
In principle, in pandas, argmin
has a skipna=True
keyword, so for pandas I would expect that an all-NaN Series behaves the same as an empty Series.