Skip to content

ZeroDivisionError when groupby rank with method="dense" and pct=True #23864

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

Merged
merged 11 commits into from
Dec 3, 2018
Merged
Prev Previous commit
Next Next commit
BUG 23666
Moved my test case from local file to approporiate test file in the repo.
  • Loading branch information
Koustav-Samaddar committed Nov 23, 2018
commit b8d343cea6c35961b8833da5cfd64a636a77869b
13 changes: 13 additions & 0 deletions pandas/tests/groupby/test_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,16 @@ def test_rank_empty_group():
result = df.groupby(column).rank(pct=True)
expected = DataFrame({"B": [0.5, np.nan, 1.0]})
tm.assert_frame_equal(result, expected)


def test_rank_zero_div():
# GH 23666
df = pd.DataFrame({
"A": [1, 1, 1, 2, 2, 2],
"B": [1, 1, 1, 1, 2, 2],
"C": [1, 2, 1, 1, 1, 2]})

try:
df.groupby(["A", "B"])["C"].rank(pct=True, method="dense")
except ZeroDivisionError:
pytest.fail("Unexpected zero division error with groupby rank")