File tree 2 files changed +12
-6
lines changed
2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -1705,17 +1705,15 @@ def __eq__(self, other: object) -> bool:
1705
1705
1706
1706
if isinstance (other , type (self )):
1707
1707
subtype = self .subtype == other .subtype
1708
- if self ._is_na_fill_value :
1708
+ if self ._is_na_fill_value or other . _is_na_fill_value :
1709
1709
# this case is complicated by two things:
1710
1710
# SparseDtype(float, float(nan)) == SparseDtype(float, np.nan)
1711
1711
# SparseDtype(float, np.nan) != SparseDtype(float, pd.NaT)
1712
1712
# i.e. we want to treat any floating-point NaN as equal, but
1713
1713
# not a floating-point NaN and a datetime NaT.
1714
- fill_value = (
1715
- other ._is_na_fill_value
1716
- and isinstance (self .fill_value , type (other .fill_value ))
1717
- or isinstance (other .fill_value , type (self .fill_value ))
1718
- )
1714
+ fill_value = isinstance (
1715
+ self .fill_value , type (other .fill_value )
1716
+ ) or isinstance (other .fill_value , type (self .fill_value ))
1719
1717
else :
1720
1718
with warnings .catch_warnings ():
1721
1719
# Ignore spurious numpy warning
Original file line number Diff line number Diff line change @@ -68,6 +68,14 @@ def test_nans_equal():
68
68
assert b == a
69
69
70
70
71
+ def test_nans_not_equal ():
72
+ # GH 54770
73
+ a = SparseDtype (float , 0 )
74
+ b = SparseDtype (float , pd .NA )
75
+ assert not a == b
76
+ assert not b == a
77
+
78
+
71
79
with warnings .catch_warnings ():
72
80
msg = "Allowing arbitrary scalar fill_value in SparseDtype is deprecated"
73
81
warnings .filterwarnings ("ignore" , msg , category = FutureWarning )
You can’t perform that action at this time.
0 commit comments