-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API/BUG: Series.argmin/max with all-NaN data returns -1 ? #33941
Comments
So this is quite explicit in the code of nanops.nanargmin/max: Lines 1171 to 1176 in 07402f6
and those lines haven't been touched in 8 years .. c1307b6 This behaviour is used in Lines 2005 to 2008 in 07402f6
The logic behind "-1" might be that in general in pandas indexers, -1 is used for missing values (and argmin kind of returns an indexer). But still, that doesn't make much sense to me for a user-facing |
if you recall we separated out argmax from idxmax a while back since argmax is not that useful in pandas (you almost always want idxmax) it’s likely understated not averse to changing to more common behavior to raise for argmax however min/max imho should just work in empty (no raise) as that is a common pandas pattern |
Yes, I know. But, which actually means that the new user-facing behaviour of argmin/argmax is rather recent (only from pandas 1.0), which is maybe a good reason that we can still fix this as a bug instead of deprecating. Now, the actual behaviour of |
On second thought, that's not fully true, since the Index classes already have been using the |
Should idxmax also work on empty Series - both truly empty Series and Series that are entirely null? Both Series.idxmax and DataFrame.idxmax currently raise, but their groupby equivalents do not (except for the special case of a categorical grouper with @jreback - I'm curious as to what common pattern you refer to above. Is it the idea that producing summary statistics (e.g. DataFrame.describe) on any data shouldn't fail? |
Discussed on last week's dev call, agreed these should be deprecated to raise. |
Ran into this while looking at #27801.
Both numpy and pandas raise an error for empty arrays/Series in
argmin
andargmax
:However, when having all NaN data, we see a different behaviour:
Does somebody have an explanation of why this would return -1 ?
In principle, in pandas,
argmin
has askipna=True
keyword, so for pandas I would expect that an all-NaN Series behaves the same as an empty Series.The text was updated successfully, but these errors were encountered: