polars.testing.assert_series_equal
-
Assert that the left and right Series are equal.
Raises a detailed
AssertionErrorif the Series 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 Series to compare.
- right
-
The second Series to compare.
- check_dtypes
-
Requires data types to match.
- check_names
-
Requires names to match.
- check_order
-
Requires elements to appear in the same order.
- 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, given as a fraction of the 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 categories.
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_series_equal >>> s1 = pl.Series([1, 2, 3]) >>> s2 = pl.Series([1, 5, 3]) >>> assert_series_equal(s1, s2) Traceback (most recent call last): ... AssertionError: Series are different (exact value mismatch) [left]: shape: (3,) Series: '' [i64] [ 1 2 3 ] [right]: shape: (3,) Series: '' [i64] [ 1 5 3 ]
polars.testing.assert_series_equal(
left: Series,
right: Series,
*,
check_dtypes: bool = True,
check_names: bool = True,
check_order: bool = True,
check_exact: bool = False,
rel_tol: float = 1e-05,
abs_tol: float = 1e-08,
categorical_as_str: bool = False,
) → None
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/api/polars.testing.assert_series_equal.html