-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: .loc with MultiIndex with names[1] = 0 #37194
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
Changes from 4 commits
02224a4
cb232f6
ea3d1a7
3073924
79a8218
8217d42
ec54357
e90d40a
cb72fc0
a91446f
f81d1cd
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 |
---|---|---|
|
@@ -1552,12 +1552,19 @@ def droplevel(self, level=0): | |
|
||
levnums = sorted(self._get_level_number(lev) for lev in level)[::-1] | ||
|
||
if len(level) == 0: | ||
return self._drop_level_nums(levnums) | ||
|
||
def _drop_level_nums(self, levnums: List[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. rename to _drop_level_number 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. sure 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. updated+green |
||
""" | ||
Drop MultiIndex levels by level _number_, not name. | ||
""" | ||
|
||
if len(levnums) == 0: | ||
return self | ||
if len(level) >= self.nlevels: | ||
if len(levnums) >= self.nlevels: | ||
raise ValueError( | ||
f"Cannot remove {len(level)} levels from an index with {self.nlevels} " | ||
"levels: at least one level must be left." | ||
f"Cannot remove {len(levnums)} levels from an index with " | ||
f"{self.nlevels} levels: at least one level must be left." | ||
) | ||
# The two checks above guarantee that here self is a MultiIndex | ||
self = cast("MultiIndex", self) | ||
|
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.
this returns an Index/MultiIndex right? (I know this code is all convoluted, but if can type pls do)
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.
tried that, mypy complained. some Index methods need to be moved to MultiIndex to get tight annotations