Skip to content

Commit 3aeba78

Browse files
authored
Fix series with none equals float series (#44195)
1 parent c2e9dd9 commit 3aeba78

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

doc/source/whatsnew/v1.3.5.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ including other versions of pandas.
1414

1515
Fixed regressions
1616
~~~~~~~~~~~~~~~~~
17+
- Fixed regression in :meth:`Series.equals` when comparing floats with dtype object to None (:issue:`44190`)
1718
- Fixed performance regression in :func:`read_csv` (:issue:`44106`)
1819
-
1920

pandas/_libs/missing.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ cpdef bint is_matching_na(object left, object right, bint nan_matches_none=False
6767
elif left is NaT:
6868
return right is NaT
6969
elif util.is_float_object(left):
70-
if nan_matches_none and right is None:
70+
if nan_matches_none and right is None and util.is_nan(left):
7171
return True
7272
return (
7373
util.is_nan(left)

pandas/tests/series/methods/test_equals.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,18 @@ def test_equals_none_vs_nan():
125125
assert ser.equals(ser2)
126126
assert Index(ser, dtype=ser.dtype).equals(Index(ser2, dtype=ser2.dtype))
127127
assert ser.array.equals(ser2.array)
128+
129+
130+
def test_equals_None_vs_float():
131+
# GH#44190
132+
left = Series([-np.inf, np.nan, -1.0, 0.0, 1.0, 10 / 3, np.inf], dtype=object)
133+
right = Series([None] * len(left))
134+
135+
# these series were found to be equal due to a bug, check that they are correctly
136+
# found to not equal
137+
assert not left.equals(right)
138+
assert not right.equals(left)
139+
assert not left.to_frame().equals(right.to_frame())
140+
assert not right.to_frame().equals(left.to_frame())
141+
assert not Index(left, dtype="object").equals(Index(right, dtype="object"))
142+
assert not Index(right, dtype="object").equals(Index(left, dtype="object"))

0 commit comments

Comments
 (0)