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_dtypes: bool = True,
- check_exact: bool = False,
- rel_tol: float = 1e-05,
- abs_tol: float = 1e-08,
- categorical_as_str: bool = False,
Assert that the left and right frame are equal.
Raises a detailed
AssertionErrorif the frames differ. This function is intended for use in unit tests.Changed in version 0.20.31: The
check_dtypeparameter was renamedcheck_dtypes.Changed in version 1.32.3: The
rtolandatolparameters were renamed torel_tolandabs_tol, respectively.- Parameters:
- left
The first DataFrame or LazyFrame to compare.
- right
The second DataFrame or LazyFrame to compare.
- check_row_order
Requires row order to match.
- check_column_order
Requires column order to match.
- check_dtypes
Requires data types to match.
- check_exact
Requires float values to match exactly. If set to
False, values are considered equal when within tolerance of each other (seerel_tolandabs_tol). Only affects columns with a Float data type.- rel_tol
Relative tolerance for inexact checking. Fraction of values in
right.- abs_tol
Absolute tolerance for inexact checking.
- categorical_as_str
Cast categorical columns to string before comparing. Enabling this helps compare columns that do not share the same string cache.
Notes
When using pytest, it may be worthwhile to shorten Python traceback printing by passing
--tb=short. The default mode tends to be unhelpfully verbose. More information in the pytest docs.Examples
>>> from polars.testing import assert_frame_equal >>> df1 = pl.DataFrame({"a": [1, 2, 3]}) >>> df2 = pl.DataFrame({"a": [1, 5, 3]}) >>> assert_frame_equal(df1, df2) Traceback (most recent call last): ... AssertionError: DataFrames are different (value mismatch for column "a") [left]: shape: (3,) Series: 'a' [i64] [ 1 2 3 ] [right]: shape: (3,) Series: 'a' [i64] [ 1 5 3 ]