-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REGR: drop raising with ea index and duplicates #45983
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4342,6 +4342,9 @@ def _drop_axis( | |
if errors == "raise" and labels_missing: | ||
raise KeyError(f"{labels} not found in axis") | ||
|
||
if is_extension_array_dtype(mask.dtype): | ||
mask = mask.to_numpy() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i guess we maybe want to define There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. opened #46025 |
||
indexer = mask.nonzero()[0] | ||
new_axis = axis.take(indexer) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -537,3 +537,15 @@ def test_drop_level_missing_label_multiindex(self): | |
df = DataFrame(index=MultiIndex.from_product([range(3), range(3)])) | ||
with pytest.raises(KeyError, match="labels \\[5\\] not found in level"): | ||
df.drop(5, level=0) | ||
|
||
@pytest.mark.parametrize("idx, level", [(["a", "b"], 0), (["a"], None)]) | ||
def test_drop_index_ea_dtype(self, any_numeric_ea_dtype, idx, level): | ||
# GH#45860 | ||
df = DataFrame( | ||
{"a": [1, 2, 2], "b": 100}, dtype=any_numeric_ea_dtype | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. case with a pd.NA? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added one more element, but this should not matter in this case I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the case i had in mind is where the BooleanArray mask that this PR casts to ndarray contains a pd.NA. Is that not reachable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah got you. I don't think so no. Having NA on both sides evaluates to False. Added the case |
||
).set_index(idx) | ||
result = df.drop(Index([2]), level=level) | ||
expected = DataFrame( | ||
{"a": [1], "b": 100}, dtype=any_numeric_ea_dtype | ||
).set_index(idx) | ||
tm.assert_frame_equal(result, expected) |
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 mask is BooleanArray, then we need to specify dtype=bool otherwise we get object dtype here. or could implement EA.nonzero.
comment with GH ref?
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.
Thx added the dtype and comment. I must have removed the dtype somehow after fixing this