Skip to content

Bug in loc returning multiindex in wrong oder with duplicated indexer #40987

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 6 commits into from
May 26, 2021

Conversation

phofl
Copy link
Member

@phofl phofl commented Apr 16, 2021

This fixes the ordering, but I am not sure if an indexer with duplicates in this case should return the same as an indexer which is unique with the same elements.

@phofl phofl added Bug Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex labels Apr 16, 2021
@jreback
Copy link
Contributor

jreback commented May 21, 2021

@phofl can you rebase and will look again

@phofl
Copy link
Member Author

phofl commented May 23, 2021

merged master

@jreback jreback added this to the 1.3 milestone May 24, 2021
),
columns=["a"],
)
result = df.loc[(slice(None), indexer), :]
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add this as an equivalent test: df_sliced = df.loc[df.index.isin(all_items, level=1), :] should yield the same expected

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 test, but should not return the same since isin produces an boolean mask, which does not reorder the underlying dataframe. This should be the identity

@jreback jreback merged commit 81eac3c into pandas-dev:master May 26, 2021
@jreback
Copy link
Contributor

jreback commented May 26, 2021

thanks @phofl

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

Successfully merging this pull request may close these issues.

BUG: slicing a MultiIndex does not preserve the sequence of the index since pandas 1.2.0rc0
2 participants