Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pandas/_libs/groupby.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,10 @@ def group_quantile(ndarray[float64_t] out,
ndarray[int64_t] counts, non_na_counts, sort_arr

assert values.shape[0] == N

if not 0 <= q <= 1:
raise ValueError("Quantile values must lie in the interval [0, 1]")

inter_methods = {
'linear': INTERPOLATION_LINEAR,
'lower': INTERPOLATION_LOWER,
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/groupby/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,18 @@ def test_groupby_transform_timezone_column(func):
tm.assert_frame_equal(result, expected)


def test_quantile_validation():
# GH#27470
df = pd.DataFrame(dict(a=[0, 0, 0, 1, 1, 1]))
g = df.groupby(np.repeat([0, 1], 3))
result = g.quantile(0.5)
expected = DataFrame(dict(a=[0.0, 1.0]))
tm.assert_frame_equal(result, expected)

with pytest.raises(ValueError, match="uantile values"):
g.quantile(1.1)


@pytest.mark.parametrize(
"func, values",
[
Expand Down