Skip to content

BUG: loc raising error for MultiIndex with bool indexer #49766

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 1 commit into from
Nov 18, 2022

Conversation

phofl
Copy link
Member

@phofl phofl commented Nov 18, 2022

@phofl phofl added Bug Indexing Related to indexing on series/frames, not to indexes themselves labels Nov 18, 2022
is_bool_dtype(ax)
or ax.dtype.name == "boolean"
or isinstance(ax, MultiIndex)
and is_bool_dtype(ax.get_level_values(0))
Copy link
Member

Choose a reason for hiding this comment

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

So if one wanted to index the bools in the second level (and the first level was not boolean), does that take a different code path?

Copy link
Member Author

@phofl phofl Nov 18, 2022

Choose a reason for hiding this comment

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

You mean something like df.loc[(slice(None), True)]?

This runs through a different path, same reason why df.loc[(True, )] worked already.

We only get there with a scalar indexer, which by definition always refers to the first level

@mroeschke mroeschke added this to the 2.0 milestone Nov 18, 2022
@mroeschke mroeschke merged commit 12aca3c into pandas-dev:main Nov 18, 2022
@mroeschke
Copy link
Member

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: can't use .loc with boolean values in MultiIndex
2 participants