polars.testing.assert_frame_equal#

polars.testing.assert_frame_equal(
left: DataFrame | LazyFrame,
right: DataFrame | LazyFrame,
*,
check_row_order: bool = True,
check_column_order: bool = True,
check_dtype: bool = True,
check_exact: bool = False,
rtol: float = 1e-05,
atol: float = 1e-08,
nans_compare_equal: bool = True,
categorical_as_str: bool = False,
) None[source]#

Raise detailed AssertionError if left does NOT equal right.

Parameters:
left

the dataframe to compare.

right

the dataframe to compare with.

check_row_order

if False, frames will compare equal if the required rows are present, irrespective of the order in which they appear; as this requires sorting, you cannot set on frames that contain unsortable columns.

check_column_order

if False, frames will compare equal if the required columns are present, irrespective of the order in which they appear.

check_dtype

if True, data types need to match exactly.

check_exact

if False, test if values are within tolerance of each other (see rtol & atol).

rtol

relative tolerance for inexact checking. Fraction of values in right.

atol

absolute tolerance for inexact checking.

nans_compare_equal

if your assert/test requires float NaN != NaN, set this to False.

categorical_as_str

Cast categorical columns to string before comparing. Enabling this helps compare dataframes that do not share the same string cache.

Examples

>>> from polars.testing import assert_frame_equal
>>> df1 = pl.DataFrame({"a": [1, 2, 3]})
>>> df2 = pl.DataFrame({"a": [2, 3, 4]})
>>> assert_frame_equal(df1, df2)  
AssertionError: Values for column 'a' are different.