Skip to content

Commit

Permalink
Backport PR #35522: BUG: Fix assert_equal when check_exact=True for n…
Browse files Browse the repository at this point in the history
…on-numeric dtypes #3… (#35652)

Co-authored-by: Isaac Virshup <[email protected]>
  • Loading branch information
meeseeksmachine and ivirshup authored Aug 10, 2020
1 parent a057e74 commit 7957254
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Fixed regressions

- Fixed regression where :meth:`DataFrame.to_numpy` would raise a ``RuntimeError`` for mixed dtypes when converting to ``str`` (:issue:`35455`)
- Fixed regression where :func:`read_csv` would raise a ``ValueError`` when ``pandas.options.mode.use_inf_as_na`` was set to ``True`` (:issue:`35493`).
- 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`)
- Fixed regression in :class:`pandas.core.groupby.RollingGroupby` where column selection was ignored (:issue:`35486`)
- Fixed regression in :meth:`DataFrame.shift` with ``axis=1`` and heterogeneous dtypes (:issue:`35488`)
- Fixed regression in ``.groupby(..).rolling(..)`` where a segfault would occur with ``center=True`` and an odd number of values (:issue:`35552`)
Expand Down
6 changes: 2 additions & 4 deletions pandas/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1339,10 +1339,8 @@ def assert_series_equal(
else:
assert_attr_equal("dtype", left, right, obj=f"Attributes of {obj}")

if check_exact:
if not is_numeric_dtype(left.dtype):
raise AssertionError("check_exact may only be used with numeric Series")

if check_exact and is_numeric_dtype(left.dtype) and is_numeric_dtype(right.dtype):
# Only check exact if dtype is numeric
assert_numpy_array_equal(
left._values,
right._values,
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/util/test_assert_series_equal.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,18 @@ class MySeries(Series):

with pytest.raises(AssertionError, match="Series classes are different"):
tm.assert_series_equal(s3, s1, check_series_type=True)


def test_series_equal_exact_for_nonnumeric():
# https://github.com/pandas-dev/pandas/issues/35446
s1 = Series(["a", "b"])
s2 = Series(["a", "b"])
s3 = Series(["b", "a"])

tm.assert_series_equal(s1, s2, check_exact=True)
tm.assert_series_equal(s2, s1, check_exact=True)

with pytest.raises(AssertionError):
tm.assert_series_equal(s1, s3, check_exact=True)
with pytest.raises(AssertionError):
tm.assert_series_equal(s3, s1, check_exact=True)

0 comments on commit 7957254

Please sign in to comment.