diff --git a/doc/source/whatsnew/v1.3.5.rst b/doc/source/whatsnew/v1.3.5.rst index ba9fcb5c1bfeb..589092c0dd7e3 100644 --- a/doc/source/whatsnew/v1.3.5.rst +++ b/doc/source/whatsnew/v1.3.5.rst @@ -14,6 +14,7 @@ including other versions of pandas. Fixed regressions ~~~~~~~~~~~~~~~~~ +- Fixed regression in :meth:`Series.equals` when comparing floats with dtype object to None (:issue:`44190`) - Fixed performance regression in :func:`read_csv` (:issue:`44106`) - diff --git a/pandas/_libs/missing.pyx b/pandas/_libs/missing.pyx index cbe79d11fbfc9..835b288778473 100644 --- a/pandas/_libs/missing.pyx +++ b/pandas/_libs/missing.pyx @@ -64,7 +64,7 @@ cpdef bint is_matching_na(object left, object right, bint nan_matches_none=False elif left is NaT: return right is NaT elif util.is_float_object(left): - if nan_matches_none and right is None: + if nan_matches_none and right is None and util.is_nan(left): return True return ( util.is_nan(left) diff --git a/pandas/tests/series/methods/test_equals.py b/pandas/tests/series/methods/test_equals.py index 0b3689afac764..a3faf783fd3fb 100644 --- a/pandas/tests/series/methods/test_equals.py +++ b/pandas/tests/series/methods/test_equals.py @@ -125,3 +125,18 @@ def test_equals_none_vs_nan(): assert ser.equals(ser2) assert Index(ser).equals(Index(ser2)) assert ser.array.equals(ser2.array) + + +def test_equals_None_vs_float(): + # GH#44190 + left = Series([-np.inf, np.nan, -1.0, 0.0, 1.0, 10 / 3, np.inf], dtype=object) + right = Series([None] * len(left)) + + # these series were found to be equal due to a bug, check that they are correctly + # found to not equal + assert not left.equals(right) + assert not right.equals(left) + assert not left.to_frame().equals(right.to_frame()) + assert not right.to_frame().equals(left.to_frame()) + assert not Index(left, dtype="object").equals(Index(right, dtype="object")) + assert not Index(right, dtype="object").equals(Index(left, dtype="object"))