Skip to content

Commit d6fa2c6

Browse files
committed
add test ranking inf/nan in descending order
1 parent ac189a1 commit d6fa2c6

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

pandas/tests/series/test_rank.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from pandas.tests.series.common import TestData
1717
from pandas._libs.tslib import iNaT
1818
from pandas._libs.algos import Infinity, NegInfinity
19+
from itertools import chain
1920

2021

2122
class TestSeriesRank(TestData):
@@ -263,8 +264,9 @@ def test_rank_tie_methods_on_infs_nans(self):
263264
chunk = 3
264265
disabled = set([('object', 'first')])
265266

266-
def _check(s, expected, method='average', na_option='keep'):
267-
result = s.rank(method=method, na_option=na_option)
267+
def _check(s, expected, method='average', na_option='keep', ascending=True):
268+
expected = list(chain.from_iterable(expected))
269+
result = s.rank(method=method, na_option=na_option, ascending=ascending)
268270
tm.assert_series_equal(result, Series(expected, dtype='float64'))
269271

270272
exp_ranks = {
@@ -283,12 +285,13 @@ def _check(s, expected, method='average', na_option='keep'):
283285
if (dtype, method) in disabled:
284286
continue
285287
if na_opt == 'top':
286-
order = ranks[1] + ranks[0] + ranks[2]
288+
order = [ranks[1], ranks[0], ranks[2]]
287289
elif na_opt == 'bottom':
288-
order = ranks[0] + ranks[2] + ranks[1]
290+
order = [ranks[0], ranks[2], ranks[1]]
289291
else:
290-
order = ranks[0] + [np.nan] * chunk + ranks[1]
291-
_check(iseries, order, method, na_opt)
292+
order = [ranks[0], [np.nan] * chunk, ranks[1]]
293+
_check(iseries, order, method, na_opt, True)
294+
_check(iseries, order[::-1], method, na_opt, False)
292295

293296
def test_rank_methods_series(self):
294297
pytest.importorskip('scipy.stats.special')

0 commit comments

Comments
 (0)