Skip to content

Commit

Permalink
Rebase and parametrize tests
Browse files Browse the repository at this point in the history
1. Moved tests to series-/frame-level test_rank (from test_stats) per pandas-dev#15658.
2. Parametrize `series/test_rank` for `pct=True`.
  • Loading branch information
rouzazari committed Apr 5, 2017
1 parent 01cb0da commit 8b261ec
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 230 deletions.
3 changes: 2 additions & 1 deletion pandas/tests/frame/test_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ def test_rank_methods_frame(self):
expected = expected.astype('float64')
tm.assert_frame_equal(result, expected)

def test_rank_dense_(self):
def test_rank_dense_method(self):
# GH15630, pct should be on 100% basis even when method='dense'
df = DataFrame([['2012', 'B', 3], ['2012', 'A', 2], ['2012', 'A', 1]])
result = df.rank(method='dense', pct=True)
expected = DataFrame([[1., 1., 1.],
Expand Down
39 changes: 20 additions & 19 deletions pandas/tests/series/test_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,25 +287,6 @@ def test_rank_dense_method(self):
expected = Series(exp).astype(result.dtype)
assert_series_equal(result, expected)

def test_rank_dense_(self):
# GH15630, pct should be on 100% basis even when method='dense'
in_out = [([1], [1.]),
([2], [1.]),
([0], [1.]),
([2, 2], [1., 1.]),
([1, 2, 3], [1. / 3, 2. / 3, 3. / 3]),
([4, 2, 1], [3. / 3, 2. / 3, 1. / 3],),
([1, 1, 5, 5, 3], [1. / 3, 1. / 3, 3. / 3, 3. / 3, 2. / 3]),
([-5, -4, -3, -2, -1],
[1. / 5, 2. / 5, 3. / 5, 4. / 5, 5. / 5])]

for ser, exp in in_out:
for dtype in dtypes:
s = Series(ser).astype(dtype)
result = s.rank(method='dense', pct=True)
expected = Series(exp).astype(result.dtype)
assert_series_equal(result, expected)

def test_rank_descending(self):
dtypes = ['O', 'f8', 'i8']

Expand Down Expand Up @@ -341,3 +322,23 @@ def test_rank_object_bug(self):
# smoke tests
Series([np.nan] * 32).astype(object).rank(ascending=True)
Series([np.nan] * 32).astype(object).rank(ascending=False)


@pytest.mark.parametrize('dtype', ['O', 'f8', 'i8'])
@pytest.mark.parametrize('ser, exp', [
([1], [1.]),
([2], [1.]),
([0], [1.]),
([2, 2], [1., 1.]),
([1, 2, 3], [1. / 3, 2. / 3, 3. / 3]),
([4, 2, 1], [3. / 3, 2. / 3, 1. / 3],),
([1, 1, 5, 5, 3], [1. / 3, 1. / 3, 3. / 3, 3. / 3, 2. / 3]),
([-5, -4, -3, -2, -1], [1. / 5, 2. / 5, 3. / 5, 4. / 5, 5. / 5])])
def test_rank_pct(dtype, ser, exp):
# GH15630, pct should be on 100% basis even when method='dense'
# TODO: add other methods (i.e. 'average', 'min', 'max', 'first')

s = Series(ser).astype(dtype)
result = s.rank(method='dense', pct=True)
expected = Series(exp).astype(result.dtype)
assert_series_equal(result, expected)
210 changes: 0 additions & 210 deletions pandas/tests/test_stats.py

This file was deleted.

0 comments on commit 8b261ec

Please sign in to comment.