I need to test that two pandas dataframes are not equal.
Is there an equivalent to pandas assert_frame_equal
function that does this? If not, what's the best/safest way to assert that the frames aren't equal?
DataFrame - equals() function The equals() function is used to test whether two objects contain the same elements. This function allows two Series or DataFrames to be compared against each other to see if they have the same shape and elements. NaNs in the same location are considered equal.
The equals() function is used to test whether two Pandas objects contain the same elements.
You could write your own assertion function that 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()
uses for comparing data frames, so the question of what constitutes equality is avoided - inequality is simply the opposite of whatever assert_frame_equal()
determines.
Yes there is :
# Let us suppose you have two dataframes df1 and df2
# Check for equality by using
df1.equals(df2)
Use not
to assert that they are not equal
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With