-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix drop_sel for a MultiIndex
#10863
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
base: main
Are you sure you want to change the base?
Conversation
Most labels passed into `drop_sel` can be handled by the underlying libraries, and will covert to an array as the current implementation does. xr.DataArray is a special case that is supported as set of labels but doesn't interact well with pandas coversion to an array.
|
Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient. |
| Data variables: | ||
| A (x, y) int64 32B 0 2 3 5 | ||
| """ | ||
| from xarray.core.dataarray import DataArray |
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've imported DataArray here as that seems to fit with the style in other parts of the codebase (here), however I'm not entirely sure why this is done.
|
I don't know this area that well, though it does seem to solve the immediate problem. would anyone have alternative approaches that get at the root of the issue? otherwise I would suggest merging this, maybe with a comment explaining, and then nothing prevents refactoring later... (adding @benbovy , the indexing Czar, though others will also know more) |
I have to admit the same! To try and provide more context I've dived down the git blame rabbit hole to explain the original reason for the cast to an array type within the code. It was introduced in this PR #3177. The PR intorduces a whole bunch of type hints for the old |
This is a proposed fix to #10862 to allow consistent usage between
selanddrop_selfor MultiIndexes. The current implementation seems to convert the labels to an array to handle the edge case of labels of typexr.DataArray. This change makes that edge case more explict and delegates the reponsibility for converting to an array if needed down to the indexer.Exisitng indexes already do this and so the change shouldn't have any preformance implications:
pandas.Index.drop- herepandas.MultiIndex.drop- hereCloses Differing behaviour between
selanddrop_selfor MultiIndexes #10862Tests added