Skip to content

Commit

Permalink
fix(python): Allow inexact checking of nested integers (#12037)
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego authored Oct 26, 2023
1 parent d6f1ecf commit f76f5b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions py-polars/polars/testing/asserts/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def assert_series_equal(
"""
if nans_compare_equal is not None:
issue_deprecation_warning(
"The `nans_compare_equal` parameter for `assert_frame_equal` is deprecated."
"The `nans_compare_equal` parameter for `assert_series_equal` is deprecated."
" Default behaviour will remain as though it were set to `True`.",
version="0.19.12",
)
Expand Down Expand Up @@ -177,7 +177,7 @@ def _assert_series_values_equal(
unequal = unequal & ~both_nan

# Check nested dtypes in separate function
if _comparing_nested_floats(left.dtype, right.dtype):
if _comparing_nested_numerics(left.dtype, right.dtype):
if _assert_series_nested(
left=left.filter(unequal),
right=right.filter(unequal),
Expand Down Expand Up @@ -309,11 +309,11 @@ def _comparing_structs(left: PolarsDataType, right: PolarsDataType) -> bool:
return left == Struct and right == Struct


def _comparing_nested_floats(left: PolarsDataType, right: PolarsDataType) -> bool:
def _comparing_nested_numerics(left: PolarsDataType, right: PolarsDataType) -> bool:
if not (_comparing_lists(left, right) or _comparing_structs(left, right)):
return False

return bool(FLOAT_DTYPES & unpack_dtypes(left, right))
return bool(NUMERIC_DTYPES & unpack_dtypes(left, right))


def _assert_series_values_within_tolerance(
Expand Down
9 changes: 9 additions & 0 deletions py-polars/tests/unit/testing/test_assert_series_equal.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,15 @@ def test_assert_series_equal_array_equal(check_exact: bool) -> None:
assert_series_equal(s1, s2, check_exact=check_exact)


def test_assert_series_equal_nested_int() -> None:
s1 = pl.Series([[1, 2], [3, 4]])
s2 = pl.Series([[1, 2], [3, 5]])

assert_series_equal(s1, s2, atol=1)
with pytest.raises(AssertionError):
assert_series_equal(s1, s2, check_exact=True)


def test_compare_series_nans_assert_equal_deprecated() -> None:
srs1 = pl.Series([1.0, 2.0, nan, 4.0, None, 6.0])
srs2 = pl.Series([1.0, nan, 3.0, 4.0, None, 6.0])
Expand Down

0 comments on commit f76f5b6

Please sign in to comment.