#NEWLINE# def test_duplicated_drop_duplicates( self ) : #NEWLINE# #INDENT# for original in self . objs : #NEWLINE# #INDENT# if isinstance ( original , Index ) : #NEWLINE# #INDENT# if original . is_boolean ( ) : #NEWLINE# #INDENT# result = original . drop_duplicates ( ) #NEWLINE# expected = Index ( [ False , True ] , name = 'a' ) #NEWLINE# tm . assert_index_equal ( result , expected ) #NEWLINE# continue #NEWLINE# #UNINDENT# expected = np . array ( ( [ False ] * len ( original ) ) , dtype = bool ) #NEWLINE# duplicated = original . duplicated ( ) #NEWLINE# tm . assert_numpy_array_equal ( duplicated , expected ) #NEWLINE# self . assertTrue ( ( duplicated . dtype == bool ) ) #NEWLINE# result = original . drop_duplicates ( ) #NEWLINE# tm . assert_index_equal ( result , original ) #NEWLINE# self . assertFalse ( ( result is original ) ) #NEWLINE# self . assertFalse ( original . has_duplicates ) #NEWLINE# idx = original [ ( list ( range ( len ( original ) ) ) + [ 5 , 3 ] ) ] #NEWLINE# expected = np . array ( ( ( [ False ] * len ( original ) ) + [ True , True ] ) , dtype = bool ) #NEWLINE# duplicated = idx . duplicated ( ) #NEWLINE# tm . assert_numpy_array_equal ( duplicated , expected ) #NEWLINE# self . assertTrue ( ( duplicated . dtype == bool ) ) #NEWLINE# tm . assert_index_equal ( idx . drop_duplicates ( ) , original ) #NEWLINE# base = ( [ False ] * len ( idx ) ) #NEWLINE# base [ 3 ] = True #NEWLINE# base [ 5 ] = True #NEWLINE# expected = np . array ( base ) #NEWLINE# duplicated = idx . duplicated ( keep = 'last' ) #NEWLINE# tm . assert_numpy_array_equal ( duplicated , expected ) #NEWLINE# self . assertTrue ( ( duplicated . dtype == bool ) ) #NEWLINE# result = idx . drop_duplicates ( keep = 'last' ) #NEWLINE# tm . assert_index_equal ( result , idx [ ( ~ expected ) ] ) #NEWLINE# with tm . assert_produces_warning ( FutureWarning ) : #NEWLINE# #INDENT# duplicated = idx . duplicated ( take_last = True ) #NEWLINE# #UNINDENT# tm . assert_numpy_array_equal ( duplicated , expected ) #NEWLINE# self . assertTrue ( ( duplicated . dtype == bool ) ) #NEWLINE# with tm . assert_produces_warning ( FutureWarning ) : #NEWLINE# #INDENT# result = idx . drop_duplicates ( take_last = True ) #NEWLINE# #UNINDENT# tm . assert_index_equal ( result , idx [ ( ~ expected ) ] ) #NEWLINE# base = ( ( [ False ] * len ( original ) ) + [ True , True ] ) #NEWLINE# base [ 3 ] = True #NEWLINE# base [ 5 ] = True #NEWLINE# expected = np . array ( base ) #NEWLINE# duplicated = idx . duplicated ( keep = False ) #NEWLINE# tm . assert_numpy_array_equal ( duplicated , expected ) #NEWLINE# self . assertTrue ( ( duplicated . dtype == bool ) ) #NEWLINE# result = idx . drop_duplicates ( keep = False ) #NEWLINE# tm . assert_index_equal ( result , idx [ ( ~ expected ) ] ) #NEWLINE# with tm . assertRaisesRegexp ( TypeError , 'drop_duplicates\\(\\) got an unexpected keyword argument' ) : #NEWLINE# #INDENT# idx . drop_duplicates ( inplace = True ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# expected = Series ( ( [ False ] * len ( original ) ) , index = original . index , name = 'a' ) #NEWLINE# tm . assert_series_equal ( original . duplicated ( ) , expected ) #NEWLINE# result = original . drop_duplicates ( ) #NEWLINE# tm . assert_series_equal ( result , original ) #NEWLINE# self . assertFalse ( ( result is original ) ) #NEWLINE# idx = original . index [ ( list ( range ( len ( original ) ) ) + [ 5 , 3 ] ) ] #NEWLINE# values = original . _values [ ( list ( range ( len ( original ) ) ) + [ 5 , 3 ] ) ] #NEWLINE# s = Series ( values , index = idx , name = 'a' ) #NEWLINE# expected = Series ( ( ( [ False ] * len ( original ) ) + [ True , True ] ) , index = idx , name = 'a' ) #NEWLINE# tm . assert_series_equal ( s . duplicated ( ) , expected ) #NEWLINE# tm . assert_series_equal ( s . drop_duplicates ( ) , original ) #NEWLINE# base = ( [ False ] * len ( values ) ) #NEWLINE# base [ 3 ] = True #NEWLINE# base [ 5 ] = True #NEWLINE# expected = Series ( base , index = idx , name = 'a' ) #NEWLINE# tm . assert_series_equal ( s . duplicated ( keep = 'last' ) , expected ) #NEWLINE# tm . assert_series_equal ( s . drop_duplicates ( keep = 'last' ) , s [ ( ~ np . array ( base ) ) ] ) #NEWLINE# with tm . assert_produces_warning ( FutureWarning ) : #NEWLINE# #INDENT# tm . assert_series_equal ( s . duplicated ( take_last = True ) , expected ) #NEWLINE# #UNINDENT# with tm . assert_produces_warning ( FutureWarning ) : #NEWLINE# #INDENT# tm . assert_series_equal ( s . drop_duplicates ( take_last = True ) , s [ ( ~ np . array ( base ) ) ] ) #NEWLINE# #UNINDENT# base = ( ( [ False ] * len ( original ) ) + [ True , True ] ) #NEWLINE# base [ 3 ] = True #NEWLINE# base [ 5 ] = True #NEWLINE# expected = Series ( base , index = idx , name = 'a' ) #NEWLINE# tm . assert_series_equal ( s . duplicated ( keep = False ) , expected ) #NEWLINE# tm . assert_series_equal ( s . drop_duplicates ( keep = False ) , s [ ( ~ np . array ( base ) ) ] ) #NEWLINE# s . drop_duplicates ( inplace = True ) #NEWLINE# tm . assert_series_equal ( s , original )