diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 9aba9723e0546..91cc878124cdc 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1895,6 +1895,8 @@ def post_processor(vals: np.ndarray, inference: Optional[Type]) -> np.ndarray: return vals + algorithms.check_percentile(q) + return self._get_cythonized_result( "group_quantile", self.grouper, diff --git a/pandas/tests/groupby/test_function.py b/pandas/tests/groupby/test_function.py index efc3142b25b82..fc4cda97620f0 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -1333,3 +1333,15 @@ def test_groupby_mean_no_overflow(): } ) assert df.groupby("user")["connections"].mean()["A"] == 3689348814740003840 + + +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="all be in the interval"): + g.quantile(1.1)