Skip to content

BUG in _unstack_multiple #32624

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

Closed
r7sa opened this issue Mar 11, 2020 · 0 comments · Fixed by #32990
Closed

BUG in _unstack_multiple #32624

r7sa opened this issue Mar 11, 2020 · 0 comments · Fixed by #32990
Labels
Bug MultiIndex Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@r7sa
Copy link

r7sa commented Mar 11, 2020

Code Sample

Next code fail to do unstack.

d = pd.DataFrame([[1,2,3],[2,2,3],[3,2,3],[4,2,3],[5,2,3]], 
                 columns=pd.MultiIndex.from_tuples([[0, 0, 0], [0, 0, 1], [0, 0, 2]], names=['c1', 'c2', 'c3']),
                 index=pd.MultiIndex.from_tuples([[0, 0, 0, 0, 0, 0, 0],
                                                  [0, 0, 1, 0, 0, 0, 1],
                                                  [0, 1, 0, 0, 0, 1, 0],
                                                  [0, 1, 1, 0, 0, 1, 1],
                                                  [1, 0, 0, 0, 1, 0, 0]
                                                  ], 
                                                 names=['i1', 'i2', 'i3', 'i4', 'i5', 'i6', 'i7']))
e = d.unstack(['i2', 'i3', 'i4', 'i5', 'i6', 'i7'])

It rise exception IndexError with message "Too many levels: Index has only 2 levels, not 3"

Problem description

The reason semms to mistyping in https://github.com/pandas-dev/pandas/blob/master/pandas/core/reshape/reshape.py#L366 :

clocs = [v if i > v else v - 1 for v in clocs]

I think it must be:

clocs = [v if val > v else v - 1 for v in clocs]
phofl pushed a commit to phofl/pandas that referenced this issue Mar 24, 2020
@simonjayhawkins simonjayhawkins added Bug MultiIndex Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Mar 25, 2020
@jreback jreback added this to the 1.1 milestone Mar 26, 2020
TomAugspurger pushed a commit that referenced this issue Mar 26, 2020
…lumns DataFrame (#32990)

* BUG: Fix bug for unstack with a lot of indices (#32624)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug MultiIndex Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants