-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Improve MultiIndex label rename checks #61769
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?
Conversation
d700c92
to
6b7cba3
Compare
pandas/core/generic.py
Outdated
indexers = [ | ||
ax.get_level_values(i).get_indexer_for([replacement]) | ||
for i in range(ax.nlevels) | ||
if i == level or level is None | ||
] |
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.
I think MultiIndex.get_indexer_for
should work with for an iterable of tuples, so I would look into why that isn't working as opposed to working around it here
6b7cba3
to
0fd6ca7
Compare
@@ -6429,12 +6429,15 @@ def _transform_index(self, func, *, level=None) -> Index: | |||
Only apply function to one level of the MultiIndex if level is specified. | |||
""" | |||
if isinstance(self, ABCMultiIndex): | |||
values = [ | |||
self.get_level_values(i).map(func) | |||
if i == level or level is None |
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.
@mroeschke - I've managed to trace this issue to this line here. The Index._transform_index
function is only used in one other place: merge.py>_items_overlap_with_suffix
Checking if this has had an adverse impact on other tests...
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.
It looks like certain existing transformations have to be applied to each individual level component of a MultiIndex
, whereas others make more sense to apply to the entire thing.
I'm guessing a new parameter to DataFrame.rename()
is needed which could then be cascaded down to Index._transform_index()
? Something like scope: {"full", "partial"}
?
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.