-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Passing multiple levels to stack when having mixed integer/string level names #8584
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
Comments
hmm, so this is an api issue then? I think we should be very strict on this as we cannot disambiguate easy (e.g.
|
I think this are examples that we can disambiguate. I understood from that PR that the new logic was:
So following that, these case should / can work I think (and it does work in some cases, so at least it is a bit inconstent). And if that logic is correct (it is the logic we want to follow), that should maybe be also mentioned in the docstring. |
I agree that these two should work, since all the levels are in the level names:
And
I had a look tonight and I think I have a fix for both cases, we just need to be a bit more careful about when we're dealing with level names and when we're dealing with level numbers. If I can get these cases working, then I think the logic you've outlined (which was the original intent of the PR) still holds. Probably a good idea to add it to the docstring though. |
The simplest solution I came up with for this involved adding an Would this be OK to add to the API, or should I add this behaviour in a new method like |
@onesandzeroes you can make an internal function (leading '_') if you need, but this shouldn't be exposed |
BUG: Passing multiple levels to stack when having mixed integer/string level names (#8584)
Related #7770
Using the example of the docs (http://pandas.pydata.org/pandas-docs/stable/reshaping.html#multiple-levels):
CONTEXT:
df.stack(level=['animal', 'hair_length'])
anddf.stack(level=[1, 2])
are equivalent (feature introduced in #7770). Mixing integers location and string names (egdf.stack(level=['animal', 2])
) gives a ValueError.But if you have level names of mixed types, some different (and wrong things) happen:
With a total different number, it still works as it should:
With the number 1, it treats the 1 as a level number instead of the level name, leading to a wrong result (two times the same level unstacked):
With the number 0, it gives a strange error:
The text was updated successfully, but these errors were encountered: