Skip to content

Commit 1b654c9

Browse files
committed
TST: Don't ignore tolerance for integer series
1 parent 9e87dc7 commit 1b654c9

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

pandas/_testing/asserters.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import numpy as np
1212

13+
from pandas._libs import lib
1314
from pandas._libs.missing import is_matching_na
1415
from pandas._libs.sparse import SparseIndex
1516
import pandas._libs.testing as _testing
@@ -811,14 +812,14 @@ def assert_series_equal(
811812
check_index_type: bool | Literal["equiv"] = "equiv",
812813
check_series_type: bool = True,
813814
check_names: bool = True,
814-
check_exact: bool = False,
815+
check_exact: bool | lib.NoDefault = lib.no_default,
815816
check_datetimelike_compat: bool = False,
816817
check_categorical: bool = True,
817818
check_category_order: bool = True,
818819
check_freq: bool = True,
819820
check_flags: bool = True,
820-
rtol: float = 1.0e-5,
821-
atol: float = 1.0e-8,
821+
rtol: float | lib.NoDefault = lib.no_default,
822+
atol: float | lib.NoDefault = lib.no_default,
822823
obj: str = "Series",
823824
*,
824825
check_index: bool = True,
@@ -877,6 +878,25 @@ def assert_series_equal(
877878
>>> tm.assert_series_equal(a, b)
878879
"""
879880
__tracebackhide__ = True
881+
if (
882+
check_exact is lib.no_default
883+
and rtol is lib.no_default
884+
and atol is lib.no_default
885+
):
886+
if (
887+
is_numeric_dtype(left.dtype)
888+
and not is_float_dtype(left.dtype)
889+
or is_numeric_dtype(right.dtype)
890+
and not is_float_dtype(right.dtype)
891+
):
892+
check_exact = True
893+
else:
894+
check_exact = False
895+
elif check_exact is lib.no_default:
896+
check_exact = False
897+
898+
rtol = rtol if rtol is not lib.no_default else 1.0e-5
899+
atol = atol if atol is not lib.no_default else 1.0e-8
880900

881901
if not check_index and check_like:
882902
raise ValueError("check_like must be False if check_index is False")
@@ -931,10 +951,7 @@ def assert_series_equal(
931951
pass
932952
else:
933953
assert_attr_equal("dtype", left, right, obj=f"Attributes of {obj}")
934-
if check_exact or (
935-
(is_numeric_dtype(left.dtype) and not is_float_dtype(left.dtype))
936-
or (is_numeric_dtype(right.dtype) and not is_float_dtype(right.dtype))
937-
):
954+
if check_exact:
938955
left_values = left._values
939956
right_values = right._values
940957
# Only check exact if dtype is numeric

pandas/tests/util/test_assert_series_equal.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,3 +462,10 @@ def test_ea_and_numpy_no_dtype_check(val, check_exact, dtype):
462462
left = Series([1, 2, val], dtype=dtype)
463463
right = Series(pd.array([1, 2, val]))
464464
tm.assert_series_equal(left, right, check_dtype=False, check_exact=check_exact)
465+
466+
467+
def test_assert_series_equal_int_tol():
468+
# GH#56646
469+
left = Series([81, 18, 121, 38, 74, 72, 81, 81, 146, 81, 81, 170, 74, 74])
470+
right = Series([72, 9, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72])
471+
tm.assert_series_equal(left, right, rtol=1.5)

0 commit comments

Comments
 (0)