-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Break reference from grouping level to MI #31133
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
BUG: Break reference from grouping level to MI #31133
Conversation
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.
is this just a regression in master? (so no note needed).
pandas/core/indexes/multi.py
Outdated
@@ -1235,6 +1235,9 @@ def _set_names(self, names, level=None, validate=True): | |||
def _get_grouper_for_level(self, mapper, level): | |||
indexer = self.codes[level] | |||
level_index = self.levels[level] | |||
# break references back to ourself so that setting the name | |||
# on the output of a groupby doesn't reflect back here. | |||
level_index = level_index.copy() |
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.
you don't need to do this here, rather do it as an else on line 1261 (add it); as take already copies, its just when that condition is not satisfied does it need a copy.
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.
Fixed, I think. Added a case for Categorical grouper with unobserved categories, so I think all the cases are covered.
Yes, this is just a regression from 0.25.x |
your comments are conflicting, if this is from 0.25.x then we need a note |
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.
lgtm (ex whether we need a whatsnew or not).
Sorry, I wasn't clear. by "from 0.25.x" I meant "after". This is fixing a regression that's only present on master, not 0.25.x. |
thanks @TomAugspurger |
…31164) Co-authored-by: Tom Augspurger <[email protected]>
Closes #31068