Skip to content

Commit dd51eb3

Browse files
ivirshupmeeseeksmachine
authored andcommitted
Backport PR pandas-dev#35522: BUG: Fix assert_equal when check_exact=True for non-numeric dtypes pandas-dev#3
1 parent 396ba93 commit dd51eb3

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

doc/source/whatsnew/v1.1.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Fixed regressions
1717

1818
- Fixed regression where :meth:`DataFrame.to_numpy` would raise a ``RuntimeError`` for mixed dtypes when converting to ``str`` (:issue:`35455`)
1919
- Fixed regression where :func:`read_csv` would raise a ``ValueError`` when ``pandas.options.mode.use_inf_as_na`` was set to ``True`` (:issue:`35493`).
20+
- Fixed regression where :func:`pandas.testing.assert_series_equal` would raise an error when non-numeric dtypes were passed with ``check_exact=True`` (:issue:`35446`)
2021
- Fixed regression in :class:`pandas.core.groupby.RollingGroupby` where column selection was ignored (:issue:`35486`)
2122
- Fixed regression in :meth:`DataFrame.shift` with ``axis=1`` and heterogeneous dtypes (:issue:`35488`)
2223
- Fixed regression in ``.groupby(..).rolling(..)`` where a segfault would occur with ``center=True`` and an odd number of values (:issue:`35552`)

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

+15
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,18 @@ 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+
tm.assert_series_equal(s1, s2, check_exact=True)
293+
tm.assert_series_equal(s2, s1, check_exact=True)
294+
295+
with pytest.raises(AssertionError):
296+
tm.assert_series_equal(s1, s3, check_exact=True)
297+
with pytest.raises(AssertionError):
298+
tm.assert_series_equal(s3, s1, check_exact=True)

0 commit comments

Comments
 (0)