Skip to content

Commit

Permalink
MAINT: Address reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyoung committed Mar 8, 2018
1 parent e0eee3d commit ddc9351
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 50 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ Offsets

Numeric
^^^^^^^
- Bug in ``DataFrame.rank()`` and ``Series.rank()`` when ``method='dense'`` and ``pct=True`` (:issue:`15630`)
- Bug in :meth:`DataFrame.rank` and :meth:`Series.rank` when ``method='dense'`` and ``pct=True`` in which percentile ranks were not being used with the number of distinct observations (:issue:`15630`)
- Bug in :class:`Series` constructor with an int or float list where specifying ``dtype=str``, ``dtype='str'`` or ``dtype='U'`` failed to convert the data elements to strings (:issue:`16605`)
- Bug in :class:`Index` multiplication and division methods where operating with a ``Series`` would return an ``Index`` object instead of a ``Series`` object (:issue:`19042`)
- Bug in the :class:`DataFrame` constructor in which data containing very large positive or very large negative numbers was causing ``OverflowError`` (:issue:`18584`)
Expand Down
76 changes: 27 additions & 49 deletions pandas/tests/frame/test_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,54 +268,32 @@ def _check2d(df, expected, method='average', axis=0):
_check2d(frame, results[method], method=method, axis=axis)


# GH15630, pct should be on 100% basis when method='dense'
@pytest.mark.parametrize('frame, exp', [
([['2012', 'B', 3], ['2012', 'A', 2], ['2012', 'A', 1]],
[[1., 1., 1.], [1., 0.5, 2. / 3], [1., 0.5, 1. / 3]])])
def test_rank_dense_pct(frame, exp):
df = DataFrame(frame)
result = df.rank(method='dense', pct=True)
expected = DataFrame(exp)
assert_frame_equal(result, expected)


@pytest.mark.parametrize('frame, exp', [
([['2012', 'B', 3], ['2012', 'A', 2], ['2012', 'A', 1]],
[[1. / 3, 1., 1.], [1. / 3, 1. / 3, 2. / 3],
[1. / 3, 1. / 3, 1. / 3]])])
def test_rank_min_pct(frame, exp):
df = DataFrame(frame)
result = df.rank(method='min', pct=True)
expected = DataFrame(exp)
assert_frame_equal(result, expected)


@pytest.mark.parametrize('frame, exp', [
([['2012', 'B', 3], ['2012', 'A', 2], ['2012', 'A', 1]],
[[1., 1., 1.], [1., 2. / 3, 2. / 3], [1., 2. / 3, 1. / 3]])])
def test_rank_max_pct(frame, exp):
df = DataFrame(frame)
result = df.rank(method='max', pct=True)
expected = DataFrame(exp)
assert_frame_equal(result, expected)


@pytest.mark.parametrize('frame, exp', [
([['2012', 'B', 3], ['2012', 'A', 2], ['2012', 'A', 1]],
[[2. / 3, 1., 1.], [2. / 3, 0.5, 2. / 3], [2. / 3, 0.5, 1. / 3]])])
def test_rank_average_pct(frame, exp):
df = DataFrame(frame)
result = df.rank(method='average', pct=True)
expected = DataFrame(exp)
assert_frame_equal(result, expected)

@pytest.mark.parametrize(
"method,exp", [("dense",
[[1., 1., 1.],
[1., 0.5, 2. / 3],
[1., 0.5, 1. / 3]]),
("min",
[[1. / 3, 1., 1.],
[1. / 3, 1. / 3, 2. / 3],
[1. / 3, 1. / 3, 1. / 3]]),
("max",
[[1., 1., 1.],
[1., 2. / 3, 2. / 3],
[1., 2. / 3, 1. / 3]]),
("average",
[[2. / 3, 1., 1.],
[2. / 3, 0.5, 2. / 3],
[2. / 3, 0.5, 1. / 3]]),
("first",
[[1. / 3, 1., 1.],
[2. / 3, 1. / 3, 2. / 3],
[3. / 3, 2. / 3, 1. / 3]])])
def test_rank_pct_true(method, exp):
# see gh-15630.

df = DataFrame([[2012, 66, 3], [2012, 65, 2], [2012, 65, 1]])
result = df.rank(method=method, pct=True)

@pytest.mark.parametrize('frame, exp', [
([[2012, 66, 3], [2012, 65, 2], [2012, 65, 1]],
[[1. / 3, 1., 1.], [2. / 3, 1. / 3, 2. / 3],
[3. / 3, 2. / 3, 1. / 3]])])
def test_rank_first_pct(frame, exp):
df = DataFrame(frame)
result = df.rank(method='first', pct=True)
expected = DataFrame(exp)
assert_frame_equal(result, expected)
tm.assert_frame_equal(result, expected)

0 comments on commit ddc9351

Please sign in to comment.