Skip to content

API/BUG: Series.argmin/max with all-NaN data returns -1 ? #33941

Closed
@jorisvandenbossche

Description

@jorisvandenbossche

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolateNeeds DiscussionRequires discussion from core team before further action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions