Skip to content

BUG: NDFrame.equals gives false negatives with dtype=object (GH8437) #8443

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 1 commit into from
Oct 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/v0.15.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1006,3 +1006,4 @@ Bug Fixes
- Bug in ``DataFrame.dropna`` that interpreted non-existent columns in the subset argument as the 'last column' (:issue:`8303`)
- Bug in Index.intersection on non-monotonic non-unique indexes (:issue:`8362`).
- Bug in masked series assignment where mismatching types would break alignment (:issue:`8387`)
- Bug in NDFrame.equals gives false negatives with dtype=object (:issue:`8437`)
4 changes: 2 additions & 2 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
ABCSparseSeries, _infer_dtype_from_scalar,
_is_null_datelike_scalar,
is_timedelta64_dtype, is_datetime64_dtype,
_possibly_infer_to_datetimelike)
_possibly_infer_to_datetimelike, array_equivalent)
from pandas.core.index import Index, MultiIndex, _ensure_index
from pandas.core.indexing import (_maybe_convert_indices, _length_of_indexer)
from pandas.core.categorical import Categorical, _maybe_to_categorical, _is_categorical
Expand Down Expand Up @@ -1057,7 +1057,7 @@ def func(c, v, o):

def equals(self, other):
if self.dtype != other.dtype or self.shape != other.shape: return False
return np.array_equal(self.values, other.values)
return array_equivalent(self.values, other.values)


class NonConsolidatableMixIn(object):
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,21 @@ def test_equals(self):
df2 = df1.set_index(['floats'], append=True)
self.assertTrue(df3.equals(df2))

# GH 8437
a = pd.Series([False, np.nan])
b = pd.Series([False, np.nan])
c = pd.Series(index=range(2))
d = pd.Series(index=range(2))
e = pd.Series(index=range(2))
f = pd.Series(index=range(2))
c[:-1] = d[:-1] = e[0] = f[0] = False
self.assertTrue(a.equals(a))
self.assertTrue(a.equals(b))
self.assertTrue(a.equals(c))
self.assertTrue(a.equals(d))
self.assertFalse(a.equals(e))
self.assertTrue(e.equals(f))

def test_describe_raises(self):
with tm.assertRaises(NotImplementedError):
tm.makePanel().describe()
Expand Down