@@ -765,6 +765,19 @@ def test_unstack_unused_level(self, cols):
765
765
expected .index = expected .index .droplevel ("C" )
766
766
tm .assert_frame_equal (result , expected )
767
767
768
+ def test_unstack_long_index (self ):
769
+ # PH 32624: Error when using a lot of indices to unstack. The error occurred only, if a lot of indices are used.
770
+ df = pd .DataFrame ([[1 ]],
771
+ columns = pd .MultiIndex .from_tuples ([[0 ]], names = ['c1' ]),
772
+ index = pd .MultiIndex .from_tuples ([[0 , 0 , 1 , 0 , 0 , 0 , 1 ]],
773
+ names = ['i1' , 'i2' , 'i3' , 'i4' , 'i5' , 'i6' , 'i7' ]))
774
+ result = df .unstack (["i2" , "i3" , "i4" , "i5" , "i6" , "i7" ])
775
+ expected = pd .DataFrame ([[1 ]],
776
+ columns = pd .MultiIndex .from_tuples ([[0 , 0 , 1 , 0 , 0 , 0 , 1 ]],
777
+ names = ['c1' , 'i2' , 'i3' , 'i4' , 'i5' , 'i6' , 'i7' ]),
778
+ index = pd .Index ([0 ], name = 'i1' ))
779
+ tm .assert_frame_equal (result , expected )
780
+
768
781
def test_unstack_nan_index (self ): # GH7466
769
782
def cast (val ):
770
783
val_str = "" if val != val else val
0 commit comments