Skip to content

Commit c40e97c

Browse files
committed
BUG: Fix assert_equal when check_exact=True for non-numeric dtypes pandas-dev#35446
1 parent cda8284 commit c40e97c

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

pandas/_testing.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1339,10 +1339,8 @@ def assert_series_equal(
13391339
else:
13401340
assert_attr_equal("dtype", left, right, obj=f"Attributes of {obj}")
13411341

1342-
if check_exact:
1343-
if not is_numeric_dtype(left.dtype):
1344-
raise AssertionError("check_exact may only be used with numeric Series")
1345-
1342+
if check_exact and is_numeric_dtype(left.dtype) and is_numeric_dtype(right.dtype):
1343+
# Only check exact if dtype is numeric
13461344
assert_numpy_array_equal(
13471345
left._values,
13481346
right._values,

pandas/tests/util/test_assert_series_equal.py

+10
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,13 @@ class MySeries(Series):
281281

282282
with pytest.raises(AssertionError, match="Series classes are different"):
283283
tm.assert_series_equal(s3, s1, check_series_type=True)
284+
285+
286+
def test_series_equal_exact_for_nonnumeric():
287+
# https://github.com/pandas-dev/pandas/issues/35446
288+
s1 = Series(["a", "b"])
289+
s2 = Series(["a", "b"])
290+
s3 = Series(["b", "a"])
291+
292+
_assert_series_equal_both(s1, s2, check_exact=True)
293+
_assert_not_series_equal_both(s1, s3, check_exact=True)

0 commit comments

Comments
 (0)