Skip to content

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