Skip to content

BUG: Set check_exact to true if dtype is int #55934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 27, 2023
8 changes: 8 additions & 0 deletions pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,14 @@ def assert_series_equal(
else:
assert_attr_equal("dtype", left, right, obj=f"Attributes of {obj}")

if (
is_integer_dtype(left.dtype)
and is_integer_dtype(right.dtype)
and isinstance(left._values, type(right._values))
and isinstance(right._values, type(left._values))
):
check_exact = True

if check_exact and is_numeric_dtype(left.dtype) and is_numeric_dtype(right.dtype):
left_values = left._values
right_values = right._values
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/util/test_assert_series_equal.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,11 @@ def test_check_dtype_false_different_reso(dtype):

with pytest.raises(AssertionError, match="Series are different"):
tm.assert_series_equal(ser_s, ser_ms, check_dtype=False)


def test_check_exact_true_for_int_dtype():
# GH 55882
left = Series([1577840521123000])
right = Series([1577840521123543])
with pytest.raises(AssertionError, match="Series are different"):
tm.assert_series_equal(left, right)