#NEWLINE# def test_insert( self ) : #NEWLINE# #INDENT# new_index = self . index . insert ( 0 , ( 'bar' , 'two' ) ) #NEWLINE# self . assertTrue ( new_index . equal_levels ( self . index ) ) #NEWLINE# self . assertEqual ( new_index [ 0 ] , ( 'bar' , 'two' ) ) #NEWLINE# new_index = self . index . insert ( 0 , ( 'abc' , 'three' ) ) #NEWLINE# tm . assert_numpy_array_equal ( new_index . levels [ 0 ] , ( list ( self . index . levels [ 0 ] ) + [ 'abc' ] ) ) #NEWLINE# tm . assert_numpy_array_equal ( new_index . levels [ 1 ] , ( list ( self . index . levels [ 1 ] ) + [ 'three' ] ) ) #NEWLINE# self . assertEqual ( new_index [ 0 ] , ( 'abc' , 'three' ) ) #NEWLINE# assertRaisesRegexp ( ValueError , 'Item must have length equal to number of levels' , self . index . insert , 0 , ( 'foo2' , ) ) #NEWLINE# left = pd . DataFrame ( [ [ 'a' , 'b' , 0 ] , [ 'b' , 'd' , 1 ] ] , columns = [ '1st' , '2nd' , '3rd' ] ) #NEWLINE# left . set_index ( [ '1st' , '2nd' ] , inplace = True ) #NEWLINE# ts = left [ '3rd' ] . copy ( deep = True ) #NEWLINE# left . loc [ ( ( 'b' , 'x' ) , '3rd' ) ] = 2 #NEWLINE# left . loc [ ( ( 'b' , 'a' ) , '3rd' ) ] = ( - 1 ) #NEWLINE# left . loc [ ( ( 'b' , 'b' ) , '3rd' ) ] = 3 #NEWLINE# left . loc [ ( ( 'a' , 'x' ) , '3rd' ) ] = 4 #NEWLINE# left . loc [ ( ( 'a' , 'w' ) , '3rd' ) ] = 5 #NEWLINE# left . loc [ ( ( 'a' , 'a' ) , '3rd' ) ] = 6 #NEWLINE# ts . loc [ ( 'b' , 'x' ) ] = 2 #NEWLINE# ts . loc [ ( 'b' , 'a' ) ] = ( - 1 ) #NEWLINE# ts . loc [ ( 'b' , 'b' ) ] = 3 #NEWLINE# ts . loc [ ( 'a' , 'x' ) ] = 4 #NEWLINE# ts . loc [ ( 'a' , 'w' ) ] = 5 #NEWLINE# ts . loc [ ( 'a' , 'a' ) ] = 6 #NEWLINE# right = pd . DataFrame ( [ [ 'a' , 'b' , 0 ] , [ 'b' , 'd' , 1 ] , [ 'b' , 'x' , 2 ] , [ 'b' , 'a' , ( - 1 ) ] , [ 'b' , 'b' , 3 ] , [ 'a' , 'x' , 4 ] , [ 'a' , 'w' , 5 ] , [ 'a' , 'a' , 6 ] ] , columns = [ '1st' , '2nd' , '3rd' ] ) #NEWLINE# right . set_index ( [ '1st' , '2nd' ] , inplace = True ) #NEWLINE# tm . assert_frame_equal ( left , right , check_dtype = False ) #NEWLINE# tm . assert_series_equal ( ts , right [ '3rd' ] ) #NEWLINE# idx = ( ( [ ( 'test1' , i ) for i in range ( 5 ) ] + [ ( 'test2' , i ) for i in range ( 6 ) ] ) + [ ( 'test' , 17 ) , ( 'test' , 18 ) ] ) #NEWLINE# left = pd . Series ( np . linspace ( 0 , 10 , 11 ) , pd . MultiIndex . from_tuples ( idx [ : ( - 2 ) ] ) ) #NEWLINE# left . loc [ ( 'test' , 17 ) ] = 11 #NEWLINE# left . ix [ ( 'test' , 18 ) ] = 12 #NEWLINE# right = pd . Series ( np . linspace ( 0 , 12 , 13 ) , pd . MultiIndex . from_tuples ( idx ) ) #NEWLINE# tm . assert_series_equal ( left , right )