Skip to content

Commit f12f1d6

Browse files
Backport PR #44195: Fix series with none equals float series (#44229)
Co-authored-by: Tobias Pitters <[email protected]>
1 parent 5fb45c9 commit f12f1d6

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

doc/source/whatsnew/v1.3.5.rst

+1
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ cpdef bint is_matching_na(object left, object right, bint nan_matches_none=False
6464
elif left is NaT:
6565
return right is NaT
6666
elif util.is_float_object(left):
67-
if nan_matches_none and right is None:
67+
if nan_matches_none and right is None and util.is_nan(left):
6868
return True
6969
return (
7070
util.is_nan(left)

pandas/tests/series/methods/test_equals.py

+15
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).equals(Index(ser2))
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)