#NEWLINE# def test_loc_index( self ) : #NEWLINE# #INDENT# orig = pd . DataFrame ( [ [ 1 , np . nan , np . nan ] , [ 2 , 3 , np . nan ] , [ np . nan , np . nan , 4 ] ] , index = list ( 'abc' ) , columns = list ( 'xyz' ) ) #NEWLINE# sparse = orig . to_sparse ( ) #NEWLINE# self . assertEqual ( sparse . loc [ ( 'a' , 'x' ) ] , 1 ) #NEWLINE# self . assertTrue ( np . isnan ( sparse . loc [ ( 'b' , 'z' ) ] ) ) #NEWLINE# self . assertEqual ( sparse . loc [ ( 'c' , 'z' ) ] , 4 ) #NEWLINE# tm . assert_sp_series_equal ( sparse . loc [ 'a' ] , orig . loc [ 'a' ] . to_sparse ( ) ) #NEWLINE# tm . assert_sp_series_equal ( sparse . loc [ 'b' ] , orig . loc [ 'b' ] . to_sparse ( ) ) #NEWLINE# tm . assert_sp_series_equal ( sparse . loc [ 'b' , : ] , orig . loc [ 'b' , : ] . to_sparse ( ) ) #NEWLINE# tm . assert_sp_series_equal ( sparse . loc [ 'b' , : ] , orig . loc [ 'b' , : ] . to_sparse ( ) ) #NEWLINE# tm . assert_sp_series_equal ( sparse . loc [ : , 'z' ] , orig . loc [ : , 'z' ] . to_sparse ( ) ) #NEWLINE# tm . assert_sp_series_equal ( sparse . loc [ : , 'z' ] , orig . loc [ : , 'z' ] . to_sparse ( ) ) #NEWLINE# result = sparse . loc [ [ 'a' , 'b' ] ] #NEWLINE# exp = orig . loc [ [ 'a' , 'b' ] ] . to_sparse ( ) #NEWLINE# tm . assert_sp_frame_equal ( result , exp ) #NEWLINE# result = sparse . loc [ [ 'a' , 'b' ] , : ] #NEWLINE# exp = orig . loc [ [ 'a' , 'b' ] , : ] . to_sparse ( ) #NEWLINE# tm . assert_sp_frame_equal ( result , exp ) #NEWLINE# result = sparse . loc [ : , [ 'x' , 'z' ] ] #NEWLINE# exp = orig . loc [ : , [ 'x' , 'z' ] ] . to_sparse ( ) #NEWLINE# tm . assert_sp_frame_equal ( result , exp ) #NEWLINE# result = sparse . loc [ ( [ 'c' , 'a' ] , [ 'x' , 'z' ] ) ] #NEWLINE# exp = orig . loc [ ( [ 'c' , 'a' ] , [ 'x' , 'z' ] ) ] . to_sparse ( ) #NEWLINE# tm . assert_sp_frame_equal ( result , exp ) #NEWLINE# result = sparse . loc [ ( ( orig . x % 2 ) == 1 ) ] #NEWLINE# exp = orig . loc [ ( ( orig . x % 2 ) == 1 ) ] . to_sparse ( ) #NEWLINE# tm . assert_sp_frame_equal ( result , exp ) #NEWLINE# result = sparse . loc [ ( ( sparse . x % 2 ) == 1 ) ] #NEWLINE# exp = orig . loc [ ( ( orig . x % 2 ) == 1 ) ] . to_sparse ( ) #NEWLINE# tm . assert_sp_frame_equal ( result , exp )