pandas 1.4.2

ParametersBackRef
assert_frame_equal(left, right, check_dtype=True, check_index_type='equiv', check_column_type='equiv', check_frame_type=True, check_less_precise=<no_default>, check_names=True, by_blocks=False, check_exact=False, check_datetimelike_compat=False, check_categorical=True, check_like=False, check_freq=True, check_flags=True, rtol=1e-05, atol=1e-08, obj='DataFrame')

This function is intended to compare two DataFrames and output any differences. Is is mostly intended for use in unit tests. Additional parameters allow varying the strictness of the equality checks performed.

Parameters

left : DataFrame

First DataFrame to compare.

right : DataFrame

Second DataFrame to compare.

check_dtype : bool, default True

Whether to check the DataFrame dtype is identical.

check_index_type : bool or {'equiv'}, default 'equiv'

Whether to check the Index class, dtype and inferred_type are identical.

check_column_type : bool or {'equiv'}, default 'equiv'

Whether to check the columns class, dtype and inferred_type are identical. Is passed as the exact argument of assert_index_equal .

check_frame_type : bool, default True

Whether to check the DataFrame class is identical.

check_less_precise : bool or int, default False

Specify comparison precision. Only used when check_exact is False. 5 digits (False) or 3 digits (True) after decimal points are compared. If int, then specify the digits to compare.

When comparing two numbers, if the first number has magnitude less than 1e-5, we compare the two numbers directly and check whether they are equivalent within the specified precision. Otherwise, we compare the ratio of the second number to the first number and check whether it is equivalent to 1 within the specified precision.

deprecated

Use :None:None:`rtol` and :None:None:`atol` instead to define relative/absolute tolerance, respectively. Similar to :None:func:`math.isclose`.

check_names : bool, default True

Whether to check that the :None:None:`names` attribute for both the :None:None:`index` and :None:None:`column` attributes of the DataFrame is identical.

by_blocks : bool, default False

Specify how to compare internal data. If False, compare by columns. If True, compare by blocks.

check_exact : bool, default False

Whether to compare number exactly.

check_datetimelike_compat : bool, default False

Compare datetime-like which is comparable ignoring dtype.

check_categorical : bool, default True

Whether to compare internal Categorical exactly.

check_like : bool, default False

If True, ignore the order of index & columns. Note: index labels must match their respective rows (same as in columns) - same labels must be with the same data.

check_freq : bool, default True

Whether to check the :None:None:`freq` attribute on a DatetimeIndex or TimedeltaIndex.

versionadded
check_flags : bool, default True

Whether to check the flags attribute.

rtol : float, default 1e-5

Relative tolerance. Only used when check_exact is False.

versionadded
atol : float, default 1e-8

Absolute tolerance. Only used when check_exact is False.

versionadded
obj : str, default 'DataFrame'

Specify object name being compared, internally used to show appropriate assertion message.

Check that left and right DataFrame are equal.

See Also

DataFrame.equals

Check DataFrame equality.

assert_series_equal

Equivalent method for asserting Series equality.

Examples

This example shows comparing two DataFrames that are equal but with columns of differing dtypes.

This example is valid syntax, but we were not able to check execution
>>> from pandas.testing import assert_frame_equal
... df1 = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})
... df2 = pd.DataFrame({'a': [1, 2], 'b': [3.0, 4.0]})

df1 equals itself.

This example is valid syntax, but we were not able to check execution
>>> assert_frame_equal(df1, df1)

df1 differs from df2 as column 'b' is of a different type.

This example is valid syntax, but we were not able to check execution
>>> assert_frame_equal(df1, df2)
Traceback (most recent call last):
...
AssertionError: Attributes of DataFrame.iloc[:, 1] (column name="b") are different

Attribute "dtype" are different [left]: int64 [right]: float64

Ignore differing dtypes in columns with check_dtype.

This example is valid syntax, but we were not able to check execution
>>> assert_frame_equal(df1, df2, check_dtype=False)
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas._testing.asserters.assert_frame_equal

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/_testing/asserters.py#1125
type: <class 'function'>
Commit: