-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Assigning boolean series with logical indexer #60127
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
BUG: Assigning boolean series with logical indexer #60127
Conversation
…hub.com/SpoopyPillow/pandas into bug_boolean_series_with_logical_indexer
I don't think the fails are related |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a unit tests to verify the LossySetitemError
isn't raised
pandas/core/dtypes/cast.py
Outdated
@@ -1918,7 +1917,13 @@ def np_can_hold_element(dtype: np.dtype, element: Any) -> Any: | |||
# i.e. there are pd.NA elements | |||
raise LossySetitemError | |||
return element | |||
# GH 57338 | |||
# Check boolean array set as object type | |||
comp = [lib.is_bool(e) for e in np.array([element]).ravel()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this implementation can be very slow. What is this trying to achieve?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I'm trying to avoid sending a LossySetitemError when I want to cast an array of booleans that is set as an object type. So if I passed in array([True, False, True], dtype=object)
to cast to a boolean dtype, the original code would raise a LossySetitemError. I basically just go through the array and check make sure each element is a boolean.
I had originally tried doing something similar to the other if statements (for different types) where they did casted = dtype.type(element)
and directly checked using casted == element
, but that doesn't work for boolean arrays because (array([1, 1, 1]) == array([True, True, True])).all()
is True
# GH 57338 | ||
# Check boolean array set as object type | ||
if tipo.kind == "O" and isinstance(element, np.ndarray): | ||
if all(lib.is_bool(e) for e in element): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if all(lib.is_bool(e) for e in element): | |
if lib.is_bool_array(element): |
This could be faster.
Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen. |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.