-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG/API Raise ValueError for non-unique stack by name #6738
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/API Raise ValueError for non-unique stack by name #6738
Conversation
|
||
|
||
def _reference_duplicate_name(names, name): | ||
""" |
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 make this a method of 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.
That's what I was thinking.
I also changed the implementation a bit. My way was buggy since it would raise whenever there was duplicates and a name
was in names
(even if name
wasn't duplicated). But I want it to only raise when name
is one of the duplicates.
@TomAugspurger my expectation would be that index names should be hashable. They're supposed to be key-esque, right? (plus tuples are still hashable). If you needed to, I'd catch the TypeError from trying to hash non-hashable object and just warn in that case. |
@TomAugspurger pls rebase....seems ok otherwise |
@TomAugspurger this closes #6319 as well? |
Should raise a ValueError when (un)stacking a DataFrame on a nonunique level. Previous behavior was to raise a KeyError (not deliberately). Closes pandas-dev#6729.
This only closes #6319 if we don't want to support pivots/crosstabs where the names are the same. But we should be able to support them. I can do a proper fix for #6319 for .14 probably. I haven't merged this because my pushes to the remote branch aren't showing up here. All I need to do is rebase, so I may just do that as I'm merging. Should just be release notes / v0.14 that have conflicts. Sound OK? |
how so you push to the remote? |
Somewhere along the way I created two branches: Making a new PR at #6849 |
Closes #6729
We should raise a ValueError when (un)stacking and referring to a non-unique index name. You can still stack and unstack by position like normal (no ambiguity there, unless your names are integers and that integer is duplicated, in which case we'll raise a ValueError).
Right now I'm assuming that index names are always hashable, but that's not necessarily true, is it? Any good ways to check the uniqueness of the names? I didn't see anything on MultiIndex that did this.