What is the difference between `assert_frame_equal` and `equals`

后端 未结 1 1882
滥情空心
滥情空心 2021-02-20 08:46

I\'m curious to find the difference between assert_frame_equal and equal. Both are for checking the equality of two data. It applies for assert_s

1条回答
  •  南方客
    南方客 (楼主)
    2021-02-20 09:20

    assert_frame_equal throws an AssertionError when two DataFrames aren't equal.

    pd.testing.assert_frame_equal(df1, df2)            # no result - pass
    
    pd.testing.assert_frame_equal(df1, pd.DataFrame()) # throws error - fail
    # AssertionError       
    

    DataFrame.equals simply returns a boolean True/False.

    df1.equals(df2)
    # True
    
    df1.equals(pd.DataFrame())
    # False    
    

    This is also the case for the other functions defined in pd.testing, which are used to develop unit tests for pandas code.

    0 讨论(0)
提交回复
热议问题