-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
ENH: Support boolean masks for iloc.__getitem__
#61162
base: main
Are you sure you want to change the base?
ENH: Support boolean masks for iloc.__getitem__
#61162
Conversation
iloc.__getitem__
iloc.__getitem__
iloc.__getitem__
iloc.__getitem__
iloc.__getitem__
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.
Thanks for the PR! Am I correct that none of the tests being modified here actually call .iloc
successfully?
pandas/tests/indexing/test_iloc.py
Outdated
} | ||
|
||
# UserWarnings from reindex of a boolean mask | ||
for idx in [None, "index", "locs"]: | ||
mask = (df.nums > 2).values | ||
if idx: | ||
mask_index = getattr(df, idx)[::-1] | ||
mask_index = getattr(df, idx if idx == "index" else "locs")[::-1] |
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.
Since idx
is not None
here, I think this can be reverted.
pandas/tests/indexing/test_iloc.py
Outdated
except ( | ||
ValueError, | ||
IndexingError, | ||
) as err: |
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.
nit: Can you collapse this back to one line
Hi! The test on lines 742-743 calls result = df.iloc[np.array([True] * len(mask), dtype=bool)]
tm.assert_frame_equal(result, df) I noticed I should add another test with false values so I have done so. result2 = df.iloc[np.array([True, False, True, False, True], dtype=bool)]
tm.assert_frame_equal(result2, DataFrame({"a": [0, 2, 4]}, index=["A", "C", "E"])) |
iloc
withSeries
as indexer fails for__getitem__
but works with__setitem__
#60994doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.