-
-
Notifications
You must be signed in to change notification settings - Fork 18.9k
BUG: Fix Index.get_level_values() mishandling of boolean, pd.NA, np.nan, and pd.NaT levels #62175
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?
Changes from 3 commits
3df788a
fe07d18
f57ddc5
eca19a2
390f3ef
629bdf9
041994c
d881247
3e63865
7f541de
703085e
3793317
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2084,7 +2084,7 @@ def _validate_index_level(self, level) -> None: | |||||||||||
verification must be done like in MultiIndex. | ||||||||||||
|
||||||||||||
""" | ||||||||||||
if isinstance(level, int): | ||||||||||||
if type(level) is int: | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a simple edge case where the Index.name is also an int
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lib.is_integer |
||||||||||||
if level < 0 and level != -1: | ||||||||||||
raise IndexError( | ||||||||||||
"Too many levels: Index has only 1 level, " | ||||||||||||
|
@@ -2094,10 +2094,12 @@ def _validate_index_level(self, level) -> None: | |||||||||||
raise IndexError( | ||||||||||||
f"Too many levels: Index has only 1 level, not {level + 1}" | ||||||||||||
) | ||||||||||||
elif level != self.name: | ||||||||||||
raise KeyError( | ||||||||||||
f"Requested level ({level}) does not match index name ({self.name})" | ||||||||||||
) | ||||||||||||
|
||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that this is a better verification that validates what is expected from the documentation.
Suggested change
|
||||||||||||
else: | ||||||||||||
if level != self.name: | ||||||||||||
raise KeyError( | ||||||||||||
f"Requested level ({level}) does not match index name ({self.name})" | ||||||||||||
) | ||||||||||||
|
||||||||||||
def _get_level_number(self, level) -> int: | ||||||||||||
self._validate_index_level(level) | ||||||||||||
|
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.
seems this change is unrelated to the rest of the PR?
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.
Yes, actually, I was trying something and forgot to undo this change. It's fixed in the latest commit.