-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: Dense ranking with percent now uses 100% basis #15639
Changes from all commits
6299790
75783f0
f036fad
78914ce
83d76b3
776ea60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -376,3 +376,96 @@ def test_rank_modify_inplace(self): | |
s.rank() | ||
result = s | ||
assert_series_equal(result, expected) | ||
|
||
|
||
# GH15630, pct should be on 100% basis when method='dense' | ||
|
||
@pytest.mark.parametrize('dtype', ['O', 'f8', 'i8']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might consider putting these in a single parameterize as well (though not as clear cut as the frame case where you can share the input frame) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah...I can't think of a clean way to do this at the moment. I'll address the other changes first, and then maybe we'll see if any inspiration strikes. Otherwise, I would leave it alone. |
||
@pytest.mark.parametrize('ser, exp', [ | ||
([1], [1.]), | ||
([1, 2], [1. / 2, 2. / 2]), | ||
([2, 2], [1., 1.]), | ||
([1, 2, 3], [1. / 3, 2. / 3, 3. / 3]), | ||
([1, 2, 2], [1. / 2, 2. / 2, 2. / 2]), | ||
([4, 2, 1], [3. / 3, 2. / 3, 1. / 3],), | ||
([1, 1, 5, 5, 3], [1. / 3, 1. / 3, 3. / 3, 3. / 3, 2. / 3]), | ||
([1, 1, 3, 3, 5, 5], [1. / 3, 1. / 3, 2. / 3, 2. / 3, 3. / 3, 3. / 3]), | ||
([-5, -4, -3, -2, -1], [1. / 5, 2. / 5, 3. / 5, 4. / 5, 5. / 5])]) | ||
def test_rank_dense_pct(dtype, ser, exp): | ||
s = Series(ser).astype(dtype) | ||
result = s.rank(method='dense', pct=True) | ||
expected = Series(exp).astype(result.dtype) | ||
assert_series_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize('dtype', ['O', 'f8', 'i8']) | ||
@pytest.mark.parametrize('ser, exp', [ | ||
([1], [1.]), | ||
([1, 2], [1. / 2, 2. / 2]), | ||
([2, 2], [1. / 2, 1. / 2]), | ||
([1, 2, 3], [1. / 3, 2. / 3, 3. / 3]), | ||
([1, 2, 2], [1. / 3, 2. / 3, 2. / 3]), | ||
([4, 2, 1], [3. / 3, 2. / 3, 1. / 3],), | ||
([1, 1, 5, 5, 3], [1. / 5, 1. / 5, 4. / 5, 4. / 5, 3. / 5]), | ||
([1, 1, 3, 3, 5, 5], [1. / 6, 1. / 6, 3. / 6, 3. / 6, 5. / 6, 5. / 6]), | ||
([-5, -4, -3, -2, -1], [1. / 5, 2. / 5, 3. / 5, 4. / 5, 5. / 5])]) | ||
def test_rank_min_pct(dtype, ser, exp): | ||
s = Series(ser).astype(dtype) | ||
result = s.rank(method='min', pct=True) | ||
expected = Series(exp).astype(result.dtype) | ||
assert_series_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize('dtype', ['O', 'f8', 'i8']) | ||
@pytest.mark.parametrize('ser, exp', [ | ||
([1], [1.]), | ||
([1, 2], [1. / 2, 2. / 2]), | ||
([2, 2], [1., 1.]), | ||
([1, 2, 3], [1. / 3, 2. / 3, 3. / 3]), | ||
([1, 2, 2], [1. / 3, 3. / 3, 3. / 3]), | ||
([4, 2, 1], [3. / 3, 2. / 3, 1. / 3],), | ||
([1, 1, 5, 5, 3], [2. / 5, 2. / 5, 5. / 5, 5. / 5, 3. / 5]), | ||
([1, 1, 3, 3, 5, 5], [2. / 6, 2. / 6, 4. / 6, 4. / 6, 6. / 6, 6. / 6]), | ||
([-5, -4, -3, -2, -1], [1. / 5, 2. / 5, 3. / 5, 4. / 5, 5. / 5])]) | ||
def test_rank_max_pct(dtype, ser, exp): | ||
s = Series(ser).astype(dtype) | ||
result = s.rank(method='max', pct=True) | ||
expected = Series(exp).astype(result.dtype) | ||
assert_series_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize('dtype', ['O', 'f8', 'i8']) | ||
@pytest.mark.parametrize('ser, exp', [ | ||
([1], [1.]), | ||
([1, 2], [1. / 2, 2. / 2]), | ||
([2, 2], [1.5 / 2, 1.5 / 2]), | ||
([1, 2, 3], [1. / 3, 2. / 3, 3. / 3]), | ||
([1, 2, 2], [1. / 3, 2.5 / 3, 2.5 / 3]), | ||
([4, 2, 1], [3. / 3, 2. / 3, 1. / 3],), | ||
([1, 1, 5, 5, 3], [1.5 / 5, 1.5 / 5, 4.5 / 5, 4.5 / 5, 3. / 5]), | ||
([1, 1, 3, 3, 5, 5], | ||
[1.5 / 6, 1.5 / 6, 3.5 / 6, 3.5 / 6, 5.5 / 6, 5.5 / 6]), | ||
([-5, -4, -3, -2, -1], [1. / 5, 2. / 5, 3. / 5, 4. / 5, 5. / 5])]) | ||
def test_rank_average_pct(dtype, ser, exp): | ||
s = Series(ser).astype(dtype) | ||
result = s.rank(method='average', pct=True) | ||
expected = Series(exp).astype(result.dtype) | ||
assert_series_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize('dtype', ['f8', 'i8']) | ||
@pytest.mark.parametrize('ser, exp', [ | ||
([1], [1.]), | ||
([1, 2], [1. / 2, 2. / 2]), | ||
([2, 2], [1. / 2, 2. / 2.]), | ||
([1, 2, 3], [1. / 3, 2. / 3, 3. / 3]), | ||
([1, 2, 2], [1. / 3, 2. / 3, 3. / 3]), | ||
([4, 2, 1], [3. / 3, 2. / 3, 1. / 3],), | ||
([1, 1, 5, 5, 3], [1. / 5, 2. / 5, 4. / 5, 5. / 5, 3. / 5]), | ||
([1, 1, 3, 3, 5, 5], [1. / 6, 2. / 6, 3. / 6, 4. / 6, 5. / 6, 6. / 6]), | ||
([-5, -4, -3, -2, -1], [1. / 5, 2. / 5, 3. / 5, 4. / 5, 5. / 5])]) | ||
def test_rank_first_pct(dtype, ser, exp): | ||
s = Series(ser).astype(dtype) | ||
result = s.rank(method='first', pct=True) | ||
expected = Series(exp).astype(result.dtype) | ||
assert_series_equal(result, expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OT: happy to clean these tests up above / parameterize and such. (next PR).