-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
any/all reductions on boolean object-typed Series #27709
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
Comments
There is an open issue about this already, I think (will try to look it up). IIRC, the bottom line is that this is numpy behaviour. |
@jorisvandenbossche Thanks! I wasn't able to find that one. So the best solution is to add an example to the docs then? |
See eg #12863 (I seem to remember another issue where I participated, but can't find anything) |
Not fully sure. From quickly reading #12863, it seems the idea is that this could be fixed in pandas. And there are also open PRs on the numpy side. |
I've read through the open and closed PRs and issues and am still confused. The issues were in general more about support # These return True
any([np.nan, False])
any([False, np.nan])
# These return False
any([None, False])
any([False, None]) The above operations yield different results, we would want to have I would therefore actually adjust the code with options 2 but this would be a behaviour breaking change.
|
On implementing a boolean based ExtensionArray I stumbled on the case that boolean arrays with missing values (which can only be
object
-typed inpandas
) are kind-of undefined behaviour in Pandas reductions withskipna=False
:The following case should return
True
according to the docstring ofSeries.any(skipna=False)
:Whereas when you do the same operation on
float
columns the behaviour is as documented:As I have not found a unit test for the above mentioned case with a boolean object column, I suspect that this is rather undefined behaviour then intended.
Three solutions come to my mind:
Series.any()
docstring.pd.Series(booleans, dtype=object).any(…)
withpd.Series(booleans, dtype=object).astype(float).any(…)
.any/all
on a mixed typed boolean series.The text was updated successfully, but these errors were encountered: