Skip to content

Commit f8582e8

Browse files
committed
Merge pull request #8443 from unutbu/dtypeO-equals
BUG: NDFrame.equals gives false negatives with dtype=object (GH8437)
2 parents 2b389b4 + 0d8c7fd commit f8582e8

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

doc/source/v0.15.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1006,3 +1006,4 @@ Bug Fixes
10061006
- Bug in ``DataFrame.dropna`` that interpreted non-existent columns in the subset argument as the 'last column' (:issue:`8303`)
10071007
- Bug in Index.intersection on non-monotonic non-unique indexes (:issue:`8362`).
10081008
- Bug in masked series assignment where mismatching types would break alignment (:issue:`8387`)
1009+
- Bug in NDFrame.equals gives false negatives with dtype=object (:issue:`8437`)

pandas/core/internals.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
ABCSparseSeries, _infer_dtype_from_scalar,
1414
_is_null_datelike_scalar,
1515
is_timedelta64_dtype, is_datetime64_dtype,
16-
_possibly_infer_to_datetimelike)
16+
_possibly_infer_to_datetimelike, array_equivalent)
1717
from pandas.core.index import Index, MultiIndex, _ensure_index
1818
from pandas.core.indexing import (_maybe_convert_indices, _length_of_indexer)
1919
from pandas.core.categorical import Categorical, _maybe_to_categorical, _is_categorical
@@ -1057,7 +1057,7 @@ def func(c, v, o):
10571057

10581058
def equals(self, other):
10591059
if self.dtype != other.dtype or self.shape != other.shape: return False
1060-
return np.array_equal(self.values, other.values)
1060+
return array_equivalent(self.values, other.values)
10611061

10621062

10631063
class NonConsolidatableMixIn(object):

pandas/tests/test_generic.py

+15
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,21 @@ def test_equals(self):
13041304
df2 = df1.set_index(['floats'], append=True)
13051305
self.assertTrue(df3.equals(df2))
13061306

1307+
# GH 8437
1308+
a = pd.Series([False, np.nan])
1309+
b = pd.Series([False, np.nan])
1310+
c = pd.Series(index=range(2))
1311+
d = pd.Series(index=range(2))
1312+
e = pd.Series(index=range(2))
1313+
f = pd.Series(index=range(2))
1314+
c[:-1] = d[:-1] = e[0] = f[0] = False
1315+
self.assertTrue(a.equals(a))
1316+
self.assertTrue(a.equals(b))
1317+
self.assertTrue(a.equals(c))
1318+
self.assertTrue(a.equals(d))
1319+
self.assertFalse(a.equals(e))
1320+
self.assertTrue(e.equals(f))
1321+
13071322
def test_describe_raises(self):
13081323
with tm.assertRaises(NotImplementedError):
13091324
tm.makePanel().describe()

0 commit comments

Comments
 (0)