-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: setting np.nan into Series[bool] #38692
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
Isn't this actually consistent with how other numpy dtypes work? We generally upcast on setitem-like operations, and for boolean this means upcasting to float (like integers also get upcasted to float)? |
I think it is consistent with how numpy works, but bool-casting is one of the cases where we often behave differently from numpy. Ideally we would consistently use find_common_type:
|
i agree with @jbrockmendel here this is something we should do correctly numpy does this because it for backwards compatibility not because it's the right thing to do we want to preserve dtypes whenever possible bools are a wart when converted to float (ideally we would actually just convert to Boolean though) |
Where is this
|
Bools are just as much a wart when converted to object dtype, though. |
If we were to change this behavior, the change would look like #38709, which uses coerce_to_target_dtype in place of the custom logic currently in Block.setitem. coerce_to_target_dtype now uses find_common_type.
I haven't looked at concat all that closely, but based on the example you gave id like that to be object too. |
what if we convert directly to Boolean here? that is the long term type we want anyhow. |
long-term that'll be nice, but its still opt-in. Plus that comes with surprising behavior changes (copy/view semantics, 1D/2D shenanigans) |
hmm I actually think changing to nullable int would totally be fine here (sure its a breaking change), but so is what you are proposing (convert to |
-1 while it is still opt-in |
or more specifically, until we have a BooleanArray-backed index, so we can keep the Series/Index behavior consistent |
It would be more consistent (and would simplify the code) if this cast to object and did not convert True/False to 1.0/0.0. ATM we have 2 tests that such a change would break.
The text was updated successfully, but these errors were encountered: