#NEWLINE# def test_assign( self ) : #NEWLINE# #INDENT# df = DataFrame ( { #NEWLINE# #INDENT# 'A' : [ 1 , 2 , 3 ] , #NEWLINE# 'B' : [ 4 , 5 , 6 ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# original = df . copy ( ) #NEWLINE# result = df . assign ( C = ( df . B / df . A ) ) #NEWLINE# expected = df . copy ( ) #NEWLINE# expected [ 'C' ] = [ 4 , 2.5 , 2 ] #NEWLINE# assert_frame_equal ( result , expected ) #NEWLINE# result = df . assign ( C = ( lambda x : ( x . B / x . A ) ) ) #NEWLINE# assert_frame_equal ( result , expected ) #NEWLINE# assert_frame_equal ( df , original ) #NEWLINE# result = df . assign ( C = [ 4 , 2.5 , 2 ] ) #NEWLINE# assert_frame_equal ( result , self ) #NEWLINE# assert_frame_equal ( df , original ) #NEWLINE# result = df . assign ( B = ( df . B / df . A ) ) #NEWLINE# expected = expected . drop ( 'B' , axis = 1 ) . rename ( columns = { #NEWLINE# #INDENT# 'C' : 'B' , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert_frame_equal ( result , expected ) #NEWLINE# result = df . assign ( A = ( df . A + df . B ) ) #NEWLINE# expected = df . copy ( ) #NEWLINE# expected [ 'A' ] = [ 5 , 7 , 9 ] #NEWLINE# assert_frame_equal ( result , expected ) #NEWLINE# result = df . assign ( A = ( lambda x : ( x . A + x . B ) ) ) #NEWLINE# assert_frame_equal ( result , expected )