@@ -324,21 +324,94 @@ def test_rank_object_bug(self):
324
324
Series ([np .nan ] * 32 ).astype (object ).rank (ascending = False )
325
325
326
326
327
+ # GH15630, pct should be on 100% basis when method='dense'
328
+
327
329
@pytest .mark .parametrize ('dtype' , ['O' , 'f8' , 'i8' ])
328
330
@pytest .mark .parametrize ('ser, exp' , [
329
331
([1 ], [1. ]),
330
- ([2 ], [1. ]),
331
- ([0 ], [1. ]),
332
+ ([1 , 2 ], [1. / 2 , 2. / 2 ]),
332
333
([2 , 2 ], [1. , 1. ]),
333
334
([1 , 2 , 3 ], [1. / 3 , 2. / 3 , 3. / 3 ]),
335
+ ([1 , 2 , 2 ], [1. / 2 , 2. / 2 , 2. / 2 ]),
334
336
([4 , 2 , 1 ], [3. / 3 , 2. / 3 , 1. / 3 ],),
335
337
([1 , 1 , 5 , 5 , 3 ], [1. / 3 , 1. / 3 , 3. / 3 , 3. / 3 , 2. / 3 ]),
338
+ ([1 , 1 , 3 , 3 , 5 , 5 ], [1. / 3 , 1. / 3 , 2. / 3 , 2. / 3 , 3. / 3 , 3. / 3 ]),
336
339
([- 5 , - 4 , - 3 , - 2 , - 1 ], [1. / 5 , 2. / 5 , 3. / 5 , 4. / 5 , 5. / 5 ])])
337
- def test_rank_pct (dtype , ser , exp ):
338
- # GH15630, pct should be on 100% basis even when method='dense'
339
- # TODO: add other methods (i.e. 'average', 'min', 'max', 'first')
340
-
340
+ def test_rank_dense_pct (dtype , ser , exp ):
341
341
s = Series (ser ).astype (dtype )
342
342
result = s .rank (method = 'dense' , pct = True )
343
343
expected = Series (exp ).astype (result .dtype )
344
344
assert_series_equal (result , expected )
345
+
346
+
347
+ @pytest .mark .parametrize ('dtype' , ['O' , 'f8' , 'i8' ])
348
+ @pytest .mark .parametrize ('ser, exp' , [
349
+ ([1 ], [1. ]),
350
+ ([1 , 2 ], [1. / 2 , 2. / 2 ]),
351
+ ([2 , 2 ], [1. / 2 , 1. / 2 ]),
352
+ ([1 , 2 , 3 ], [1. / 3 , 2. / 3 , 3. / 3 ]),
353
+ ([1 , 2 , 2 ], [1. / 3 , 2. / 3 , 2. / 3 ]),
354
+ ([4 , 2 , 1 ], [3. / 3 , 2. / 3 , 1. / 3 ],),
355
+ ([1 , 1 , 5 , 5 , 3 ], [1. / 5 , 1. / 5 , 4. / 5 , 4. / 5 , 3. / 5 ]),
356
+ ([1 , 1 , 3 , 3 , 5 , 5 ], [1. / 6 , 1. / 6 , 3. / 6 , 3. / 6 , 5. / 6 , 5. / 6 ]),
357
+ ([- 5 , - 4 , - 3 , - 2 , - 1 ], [1. / 5 , 2. / 5 , 3. / 5 , 4. / 5 , 5. / 5 ])])
358
+ def test_rank_min_pct (dtype , ser , exp ):
359
+ s = Series (ser ).astype (dtype )
360
+ result = s .rank (method = 'min' , pct = True )
361
+ expected = Series (exp ).astype (result .dtype )
362
+ assert_series_equal (result , expected )
363
+
364
+
365
+ @pytest .mark .parametrize ('dtype' , ['O' , 'f8' , 'i8' ])
366
+ @pytest .mark .parametrize ('ser, exp' , [
367
+ ([1 ], [1. ]),
368
+ ([1 , 2 ], [1. / 2 , 2. / 2 ]),
369
+ ([2 , 2 ], [1. , 1. ]),
370
+ ([1 , 2 , 3 ], [1. / 3 , 2. / 3 , 3. / 3 ]),
371
+ ([1 , 2 , 2 ], [1. / 3 , 3. / 3 , 3. / 3 ]),
372
+ ([4 , 2 , 1 ], [3. / 3 , 2. / 3 , 1. / 3 ],),
373
+ ([1 , 1 , 5 , 5 , 3 ], [2. / 5 , 2. / 5 , 5. / 5 , 5. / 5 , 3. / 5 ]),
374
+ ([1 , 1 , 3 , 3 , 5 , 5 ], [2. / 6 , 2. / 6 , 4. / 6 , 4. / 6 , 6. / 6 , 6. / 6 ]),
375
+ ([- 5 , - 4 , - 3 , - 2 , - 1 ], [1. / 5 , 2. / 5 , 3. / 5 , 4. / 5 , 5. / 5 ])])
376
+ def test_rank_max_pct (dtype , ser , exp ):
377
+ s = Series (ser ).astype (dtype )
378
+ result = s .rank (method = 'max' , pct = True )
379
+ expected = Series (exp ).astype (result .dtype )
380
+ assert_series_equal (result , expected )
381
+
382
+
383
+ @pytest .mark .parametrize ('dtype' , ['O' , 'f8' , 'i8' ])
384
+ @pytest .mark .parametrize ('ser, exp' , [
385
+ ([1 ], [1. ]),
386
+ ([1 , 2 ], [1. / 2 , 2. / 2 ]),
387
+ ([2 , 2 ], [1.5 / 2 , 1.5 / 2 ]),
388
+ ([1 , 2 , 3 ], [1. / 3 , 2. / 3 , 3. / 3 ]),
389
+ ([1 , 2 , 2 ], [1. / 3 , 2.5 / 3 , 2.5 / 3 ]),
390
+ ([4 , 2 , 1 ], [3. / 3 , 2. / 3 , 1. / 3 ],),
391
+ ([1 , 1 , 5 , 5 , 3 ], [1.5 / 5 , 1.5 / 5 , 4.5 / 5 , 4.5 / 5 , 3. / 5 ]),
392
+ ([1 , 1 , 3 , 3 , 5 , 5 ],
393
+ [1.5 / 6 , 1.5 / 6 , 3.5 / 6 , 3.5 / 6 , 5.5 / 6 , 5.5 / 6 ]),
394
+ ([- 5 , - 4 , - 3 , - 2 , - 1 ], [1. / 5 , 2. / 5 , 3. / 5 , 4. / 5 , 5. / 5 ])])
395
+ def test_rank_average_pct (dtype , ser , exp ):
396
+ s = Series (ser ).astype (dtype )
397
+ result = s .rank (method = 'average' , pct = True )
398
+ expected = Series (exp ).astype (result .dtype )
399
+ assert_series_equal (result , expected )
400
+
401
+
402
+ @pytest .mark .parametrize ('dtype' , ['f8' , 'i8' ])
403
+ @pytest .mark .parametrize ('ser, exp' , [
404
+ ([1 ], [1. ]),
405
+ ([1 , 2 ], [1. / 2 , 2. / 2 ]),
406
+ ([2 , 2 ], [1. / 2 , 2. / 2. ]),
407
+ ([1 , 2 , 3 ], [1. / 3 , 2. / 3 , 3. / 3 ]),
408
+ ([1 , 2 , 2 ], [1. / 3 , 2. / 3 , 3. / 3 ]),
409
+ ([4 , 2 , 1 ], [3. / 3 , 2. / 3 , 1. / 3 ],),
410
+ ([1 , 1 , 5 , 5 , 3 ], [1. / 5 , 2. / 5 , 4. / 5 , 5. / 5 , 3. / 5 ]),
411
+ ([1 , 1 , 3 , 3 , 5 , 5 ], [1. / 6 , 2. / 6 , 3. / 6 , 4. / 6 , 5. / 6 , 6. / 6 ]),
412
+ ([- 5 , - 4 , - 3 , - 2 , - 1 ], [1. / 5 , 2. / 5 , 3. / 5 , 4. / 5 , 5. / 5 ])])
413
+ def test_rank_first_pct (dtype , ser , exp ):
414
+ s = Series (ser ).astype (dtype )
415
+ result = s .rank (method = 'first' , pct = True )
416
+ expected = Series (exp ).astype (result .dtype )
417
+ assert_series_equal (result , expected )
0 commit comments