Skip to content

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

Merged
merged 4 commits into from
Feb 16, 2022
Merged

Conversation

phofl
Copy link
Member

@phofl phofl commented Feb 14, 2022

We handle this case similarly for loc

@phofl phofl added Regression Functionality that used to work in a prior pandas version ExtensionArray Extending pandas with custom dtypes or arrays. Index Related to the Index class or subclasses labels Feb 14, 2022
@phofl phofl added this to the 1.4.2 milestone Feb 14, 2022
@@ -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()
Copy link
Member

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?

Copy link
Member Author

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

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
Copy link
Member

Choose a reason for hiding this comment

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

case with a pd.NA?

Copy link
Member Author

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The 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

if is_extension_array_dtype(mask.dtype):
# GH#45860
mask = mask.to_numpy(dtype=bool)

Copy link
Contributor

Choose a reason for hiding this comment

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

i guess we maybe want to define .nonzero() on EA arrays

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Member Author

Choose a reason for hiding this comment

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

opened #46025

@jreback jreback merged commit d0c36ab into pandas-dev:main Feb 16, 2022
@jreback
Copy link
Contributor

jreback commented Feb 16, 2022

@meeseeksdev backport 1.4.x

@lumberbot-app
Copy link

lumberbot-app bot commented Feb 16, 2022

Something went wrong ... Please have a look at my logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExtensionArray Extending pandas with custom dtypes or arrays. Index Related to the Index class or subclasses Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Pandas 1.4; df.drop method raises an AttributeError when Int64 index is used and index is not unique
3 participants