Skip to content

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

Conversation

SpoopyPillow
Copy link
Contributor

@SpoopyPillow
Copy link
Contributor Author

I don't think the fails are related

Copy link
Member

@mroeschke mroeschke left a 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

@@ -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()]
Copy link
Member

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?

Copy link
Contributor Author

@SpoopyPillow SpoopyPillow Oct 30, 2024

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

@mroeschke mroeschke added the Indexing Related to indexing on series/frames, not to indexes themselves label Oct 30, 2024
# 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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if all(lib.is_bool(e) for e in element):
if lib.is_bool_array(element):

This could be faster.

@mroeschke
Copy link
Member

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.

@mroeschke mroeschke closed this Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Incompatible dype warning when assigning boolean series with logical indexer
3 participants