-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: re-allow duplicate index level names #21423
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
API: re-allow duplicate index level names #21423
Conversation
59cc3dd
to
511ee38
Compare
Codecov Report
@@ Coverage Diff @@
## master #21423 +/- ##
==========================================
+ Coverage 91.9% 91.9% +<.01%
==========================================
Files 154 154
Lines 49558 49560 +2
==========================================
+ Hits 45545 45548 +3
+ Misses 4013 4012 -1
Continue to review full report at Codecov.
|
+1 in general. Will want a semi-detailed release note, potentially laying out future plans with respect to duplicate names? |
Until we don't exactly know what those future plans are, I would rather keep it limited (only noting that duplicated level names are allowed again?) |
@jreback @toobaz ready for review I went through the tests and added back some of the tests removed in #18882 I also added back |
That was also the original intent of: pandas/pandas/core/indexes/multi.py Lines 771 to 776 in a620e72
where already an informative ValueError is raised, but now the ValueError is catched, and then a generic KeyError is raised (this was changed 5 years ago: bdf270c#diff-dc96e62847cdfe77b570cf9c6b0e8086R1536) |
Agreed. |
@@ -115,6 +115,12 @@ def __init__(self, values, index, level=-1, value_columns=None, | |||
|
|||
self.index = index.remove_unused_levels() | |||
|
|||
if isinstance(self.index, MultiIndex): |
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 would rather not add API here. why don't you just do this check inside _get_level_number
itself, and then also add to Index
so you don't also have to add an instance check?
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.
Did you read my comment in the main thread?
This code above is exactly how it was before. As I said, I also think this is better in get_level_number, but propose to do a follow-up PR that can be merged for 0.24.0, as it gives an additional API change (change in error type)
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.
then let's just wait till 0.24.0 to do this.
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 seems like a good fix for the regression, why not merge it? It's no different that reverting a previous commit.
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, it is how it was for a long time, and this is fixing a regression so it is the point to do it now and not wait for 0.24.0.
I can certainly do the PR for 0.24.0 to further clean this up, but that will involve an API change so I will not do that in this PR.
fair enough, is there an issue to clean this up? |
Opened the PR to not forget his (#21678), but as mentioned, we first need to discuss the other issue. |
(cherry picked from commit 66b517c)
(cherry picked from commit 66b517c)
One possible solution for #19029
WIP (need to clean up tests and possibly re-add some ones that have been removed in #18882)