Skip to content

BUG/API: other object type check in Series/DataFrame.equals #34402

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
Jul 15, 2020
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,8 @@ Other
- Bug in :meth:`DataFrame.__dir__` caused a segfault when using unicode surrogates in a column name (:issue:`25509`)
- Bug in :meth:`DataFrame.plot.scatter` caused an error when plotting variable marker sizes (:issue:`32904`)
- :class:`IntegerArray` now implements the ``sum`` operation (:issue:`33172`)
- Bug in :meth:`DataFrame.equals` and :meth:`Series.equals` in allowing subclasses
to be equal (:issue:`34402`).
- Bug in :class:`Tick` comparisons raising ``TypeError`` when comparing against timedelta-like objects (:issue:`34088`)
- Bug in :class:`Tick` multiplication raising ``TypeError`` when multiplying by a float (:issue:`34486`)

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ def equals(self, other):
>>> df.equals(different_data_type)
False
"""
if not isinstance(other, self._constructor):
if not (isinstance(other, type(self)) or isinstance(self, type(other))):
return False
return self._mgr.equals(other._mgr)

Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,15 @@ def test_equals(self):
assert a.equals(e)
assert e.equals(f)

def test_equals_subclass(self):
# https://github.com/pandas-dev/pandas/pull/34402
s1 = pd.Series([1, 2, 3])
s2 = tm.SubclassedSeries([1, 2, 3])

# allow subclass in both directions
assert s1.equals(s2)
assert s2.equals(s1)

def test_pipe(self):
df = DataFrame({"A": [1, 2, 3]})
f = lambda x, y: x ** y
Expand Down