File tree 3 files changed +15
-2
lines changed
3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -157,7 +157,7 @@ ExtensionArray
157
157
158
158
Other
159
159
^^^^^
160
- -
160
+ - Bug in :meth: ` Series.rank ` incorrectly treating int64 min value as NaN ( :issue: ` 32859 `)
161
161
-
162
162
163
163
.. ---------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -840,7 +840,7 @@ def rank_1d(
840
840
elif rank_t is float64_t:
841
841
mask = np.isnan(values)
842
842
elif rank_t is int64_t:
843
- mask = values == NPY_NAT
843
+ mask = missing.isnaobj( values)
844
844
845
845
# create copy in case of NPY_NAT
846
846
# values are mutated inplace
Original file line number Diff line number Diff line change @@ -1769,6 +1769,19 @@ def test_basic(self):
1769
1769
s = Series ([1 , 100 ], dtype = dtype )
1770
1770
tm .assert_numpy_array_equal (algos .rank (s ), exp )
1771
1771
1772
+ @pytest .mark .parametrize ("dtype" , ["int32" , "int64" ])
1773
+ def test_negative_min_rank (self , dtype ):
1774
+ # GH#32859
1775
+ # Check that nan is respected on float64
1776
+ s = pd .Series (np .array ([np .inf , np .nan , - np .inf ]))
1777
+ expected = pd .Series (np .array ([2.0 , np .nan , 1.0 ]))
1778
+ tm .assert_series_equal (s .rank (na_option = "keep" ), expected )
1779
+
1780
+ # Rank works if coverted to most negative value
1781
+ s = pd .Series (np .array ([np .inf , np .nan , - np .inf ]).astype (dtype ))
1782
+ expected = pd .Series (np .array ([2.0 , 2.0 , 2.0 ]))
1783
+ tm .assert_series_equal (s .rank (na_option = "keep" ), expected )
1784
+
1772
1785
def test_uint64_overflow (self ):
1773
1786
exp = np .array ([1 , 2 ], dtype = np .float64 )
1774
1787
You can’t perform that action at this time.
0 commit comments