#NEWLINE# def test_take_fill_value( self ) : #NEWLINE# #INDENT# vals = [ [ 'A' , 'B' ] , [ pd . Timestamp ( '2011-01-01' ) , pd . Timestamp ( '2011-01-02' ) ] ] #NEWLINE# idx = pd . MultiIndex . from_product ( vals , names = [ 'str' , 'dt' ] ) #NEWLINE# result = idx . take ( np . array ( [ 1 , 0 , ( - 1 ) ] ) ) #NEWLINE# exp_vals = [ ( 'A' , pd . Timestamp ( '2011-01-02' ) ) , ( 'A' , pd . Timestamp ( '2011-01-01' ) ) , ( 'B' , pd . Timestamp ( '2011-01-02' ) ) ] #NEWLINE# expected = pd . MultiIndex . from_tuples ( exp_vals , names = [ 'str' , 'dt' ] ) #NEWLINE# tm . assert_index_equal ( result , expected ) #NEWLINE# result = idx . take ( np . array ( [ 1 , 0 , ( - 1 ) ] ) , fill_value = True ) #NEWLINE# exp_vals = [ ( 'A' , pd . Timestamp ( '2011-01-02' ) ) , ( 'A' , pd . Timestamp ( '2011-01-01' ) ) , ( np . nan , pd . NaT ) ] #NEWLINE# expected = pd . MultiIndex . from_tuples ( exp_vals , names = [ 'str' , 'dt' ] ) #NEWLINE# tm . assert_index_equal ( result , expected ) #NEWLINE# result = idx . take ( np . array ( [ 1 , 0 , ( - 1 ) ] ) , allow_fill = False , fill_value = True ) #NEWLINE# exp_vals = [ ( 'A' , pd . Timestamp ( '2011-01-02' ) ) , ( 'A' , pd . Timestamp ( '2011-01-01' ) ) , ( 'B' , pd . Timestamp ( '2011-01-02' ) ) ] #NEWLINE# expected = pd . MultiIndex . from_tuples ( exp_vals , names = [ 'str' , 'dt' ] ) #NEWLINE# tm . assert_index_equal ( result , expected ) #NEWLINE# msg = 'When allow_fill=True and fill_value is not None, all indices must be >= -1' #NEWLINE# with tm . assertRaisesRegexp ( ValueError , msg ) : #NEWLINE# #INDENT# idx . take ( np . array ( [ 1 , 0 , ( - 2 ) ] ) , fill_value = True ) #NEWLINE# #UNINDENT# with tm . assertRaisesRegexp ( ValueError , msg ) : #NEWLINE# #INDENT# idx . take ( np . array ( [ 1 , 0 , ( - 5 ) ] ) , fill_value = True ) #NEWLINE# #UNINDENT# with tm . assertRaises ( IndexError ) : #NEWLINE# #INDENT# idx . take ( np . array ( [ 1 , ( - 5 ) ] ) )