Skip to content

Commit 9a06c93

Browse files
rouzazarigfyoung
authored andcommitted
Rebase and parametrize tests
1. Moved tests to series-/frame-level test_rank (from test_stats) per #15658. 2. Parametrize `series/test_rank` for `pct=True`.
1 parent c90ddbc commit 9a06c93

File tree

3 files changed

+22
-230
lines changed

3 files changed

+22
-230
lines changed

pandas/tests/frame/test_rank.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ def test_rank_methods_frame(self):
217217
expected = expected.astype('float64')
218218
tm.assert_frame_equal(result, expected)
219219

220-
def test_rank_dense_(self):
220+
def test_rank_dense_method(self):
221+
# GH15630, pct should be on 100% basis even when method='dense'
221222
df = DataFrame([['2012', 'B', 3], ['2012', 'A', 2], ['2012', 'A', 1]])
222223
result = df.rank(method='dense', pct=True)
223224
expected = DataFrame([[1., 1., 1.],

pandas/tests/series/test_rank.py

+20-19
Original file line numberDiff line numberDiff line change
@@ -331,25 +331,6 @@ def test_rank_dense_method(self):
331331
expected = Series(exp).astype(result.dtype)
332332
assert_series_equal(result, expected)
333333

334-
def test_rank_dense_(self):
335-
# GH15630, pct should be on 100% basis even when method='dense'
336-
in_out = [([1], [1.]),
337-
([2], [1.]),
338-
([0], [1.]),
339-
([2, 2], [1., 1.]),
340-
([1, 2, 3], [1. / 3, 2. / 3, 3. / 3]),
341-
([4, 2, 1], [3. / 3, 2. / 3, 1. / 3],),
342-
([1, 1, 5, 5, 3], [1. / 3, 1. / 3, 3. / 3, 3. / 3, 2. / 3]),
343-
([-5, -4, -3, -2, -1],
344-
[1. / 5, 2. / 5, 3. / 5, 4. / 5, 5. / 5])]
345-
346-
for ser, exp in in_out:
347-
for dtype in dtypes:
348-
s = Series(ser).astype(dtype)
349-
result = s.rank(method='dense', pct=True)
350-
expected = Series(exp).astype(result.dtype)
351-
assert_series_equal(result, expected)
352-
353334
def test_rank_descending(self):
354335
dtypes = ['O', 'f8', 'i8']
355336

@@ -395,3 +376,23 @@ def test_rank_modify_inplace(self):
395376
s.rank()
396377
result = s
397378
assert_series_equal(result, expected)
379+
380+
381+
@pytest.mark.parametrize('dtype', ['O', 'f8', 'i8'])
382+
@pytest.mark.parametrize('ser, exp', [
383+
([1], [1.]),
384+
([2], [1.]),
385+
([0], [1.]),
386+
([2, 2], [1., 1.]),
387+
([1, 2, 3], [1. / 3, 2. / 3, 3. / 3]),
388+
([4, 2, 1], [3. / 3, 2. / 3, 1. / 3],),
389+
([1, 1, 5, 5, 3], [1. / 3, 1. / 3, 3. / 3, 3. / 3, 2. / 3]),
390+
([-5, -4, -3, -2, -1], [1. / 5, 2. / 5, 3. / 5, 4. / 5, 5. / 5])])
391+
def test_rank_pct(dtype, ser, exp):
392+
# GH15630, pct should be on 100% basis even when method='dense'
393+
# TODO: add other methods (i.e. 'average', 'min', 'max', 'first')
394+
395+
s = Series(ser).astype(dtype)
396+
result = s.rank(method='dense', pct=True)
397+
expected = Series(exp).astype(result.dtype)
398+
assert_series_equal(result, expected)

pandas/tests/test_stats.py

-210
This file was deleted.

0 commit comments

Comments
 (0)