#NEWLINE# def test_to_hierarchical( self ) : #NEWLINE# #INDENT# index = MultiIndex . from_tuples ( [ ( 1 , 'one' ) , ( 1 , 'two' ) , ( 2 , 'one' ) , ( 2 , 'two' ) ] ) #NEWLINE# result = index . to_hierarchical ( 3 ) #NEWLINE# expected = MultiIndex ( levels = [ [ 1 , 2 ] , [ 'one' , 'two' ] ] , labels = [ [ 0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 1 ] , [ 0 , 0 , 0 , 1 , 1 , 1 , 0 , 0 , 0 , 1 , 1 , 1 ] ] ) #NEWLINE# tm . assert_index_equal ( result , expected ) #NEWLINE# self . assertEqual ( result . names , index . names ) #NEWLINE# result = index . to_hierarchical ( 3 , 2 ) #NEWLINE# expected = MultiIndex ( levels = [ [ 1 , 2 ] , [ 'one' , 'two' ] ] , labels = [ [ 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 ] , [ 0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 1 ] ] ) #NEWLINE# tm . assert_index_equal ( result , expected ) #NEWLINE# self . assertEqual ( result . names , index . names ) #NEWLINE# index = MultiIndex . from_tuples ( [ ( 2 , 'c' ) , ( 1 , 'b' ) , ( 2 , 'a' ) , ( 2 , 'b' ) ] , names = [ 'N1' , 'N2' ] ) #NEWLINE# result = index . to_hierarchical ( 2 ) #NEWLINE# expected = MultiIndex . from_tuples ( [ ( 2 , 'c' ) , ( 2 , 'c' ) , ( 1 , 'b' ) , ( 1 , 'b' ) , ( 2 , 'a' ) , ( 2 , 'a' ) , ( 2 , 'b' ) , ( 2 , 'b' ) ] , names = [ 'N1' , 'N2' ] ) #NEWLINE# tm . assert_index_equal ( result , expected ) #NEWLINE# self . assertEqual ( result . names , index . names )