16
16
from pandas .tests .series .common import TestData
17
17
from pandas ._libs .tslib import iNaT
18
18
from pandas ._libs .algos import Infinity , NegInfinity
19
+ from itertools import chain
19
20
20
21
21
22
class TestSeriesRank (TestData ):
@@ -263,8 +264,9 @@ def test_rank_tie_methods_on_infs_nans(self):
263
264
chunk = 3
264
265
disabled = set ([('object' , 'first' )])
265
266
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 )
268
270
tm .assert_series_equal (result , Series (expected , dtype = 'float64' ))
269
271
270
272
exp_ranks = {
@@ -283,12 +285,13 @@ def _check(s, expected, method='average', na_option='keep'):
283
285
if (dtype , method ) in disabled :
284
286
continue
285
287
if na_opt == 'top' :
286
- order = ranks [1 ] + ranks [0 ] + ranks [2 ]
288
+ order = [ ranks [1 ], ranks [0 ], ranks [2 ] ]
287
289
elif na_opt == 'bottom' :
288
- order = ranks [0 ] + ranks [2 ] + ranks [1 ]
290
+ order = [ ranks [0 ], ranks [2 ], ranks [1 ] ]
289
291
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 )
292
295
293
296
def test_rank_methods_series (self ):
294
297
pytest .importorskip ('scipy.stats.special' )
0 commit comments