Skip to content

Commit d449a91

Browse files
committed
added test cases, to test ranking of inf and nan values
1 parent 7b077ac commit d449a91

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pandas/tests/frame/methods/test_rank.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,16 @@ def test_pct_max_many_rows(self):
329329
)
330330
result = df.rank(pct=True).max()
331331
assert (result == 1).all()
332+
333+
def test_rank_minus_inf_keep_na(self):
334+
# GH 32593
335+
expected_df = DataFrame({'col': np.array([2.0, 4.0, np.nan, 3.0, 1.0])})
336+
result_df = DataFrame({'col': np.array([1, np.inf, np.nan, 10, -np.inf])}).rank(na_option='keep')
337+
tm.assert_frame_equal(expected_df, result_df)
338+
339+
def test_rank_inf_keep_na(self):
340+
expected_df = DataFrame({'col': np.array([1.0, 2.0, 3.0])})
341+
result_df = DataFrame({'col': np.array([-np.inf, 0, np.inf])}).rank(na_option='keep')
342+
tm.assert_frame_equal(expected_df, result_df)
343+
344+

0 commit comments

Comments
 (0)