Approval of two frames is not equal

I need to check that the two pandas frames are not equal. Is there an equivalent to the pandas assert_frame_equal function that does this? If not, what is the best / safest way to claim frames are not equal?

+5
source share
3 answers

You can write your own statement function, which uses assert_frame_equal() and inverts the result:

 def assert_frame_not_equal(*args, **kwargs): try: assert_frame_equal(*args, **kwargs) except AssertionError: # frames are not equal pass else: # frames are equal raise AssertionError 

This will use the same logic that assert_frame_equal() to compare data frames, so the question of what constitutes equality is avoided - inequality is just the opposite of what assert_frame_equal() defines.

+5
source

Assuming assert_frame_equal behaves like assert (meaning nothing is happening or it is not raising an AssertionError ), then you can probably just wrap it in try :

 def assert_frame_not_equal(df1, df2): try: assert_frame_equal(df1, df2) raise AssertionError('DataFrames are equal.') except AssertionError: pass 

Add *args and / or **kwargs as desired for flexibility.

+2
source

Yes there is:

 # Let us suppose you have two dataframes df1 and df2 # Check for equality by using df1.equals(df2) 

Use not to say they are not equal

-1
source

All Articles