diff --git a/pandas/tests/series/methods/test_quantile.py b/pandas/tests/series/methods/test_quantile.py index 190cdf5f57ea3..40dee1bb17155 100644 --- a/pandas/tests/series/methods/test_quantile.py +++ b/pandas/tests/series/methods/test_quantile.py @@ -43,6 +43,11 @@ def test_quantile(self, datetime_series): with pytest.raises(ValueError, match=msg): datetime_series.quantile(invalid) + s = Series(np.random.randn(100)) + percentile_array = [-0.5, 0.25, 1.5] + with pytest.raises(ValueError, match=msg): + s.quantile(percentile_array) + def test_quantile_multi(self, datetime_series): qs = [0.1, 0.9] result = datetime_series.quantile(qs) diff --git a/pandas/util/_validators.py b/pandas/util/_validators.py index 2af68dc3d6df0..517b88b0cd938 100644 --- a/pandas/util/_validators.py +++ b/pandas/util/_validators.py @@ -329,12 +329,13 @@ def validate_percentile(q: float | Iterable[float]) -> np.ndarray: q_arr = np.asarray(q) # Don't change this to an f-string. The string formatting # is too expensive for cases where we don't need it. - msg = "percentiles should all be in the interval [0, 1]. Try {} instead." + msg = "percentiles should all be in the interval [0, 1]" if q_arr.ndim == 0: if not 0 <= q_arr <= 1: - raise ValueError(msg.format(q_arr / 100.0)) - elif not all(0 <= qs <= 1 for qs in q_arr): - raise ValueError(msg.format(q_arr / 100.0)) + raise ValueError(msg) + else: + if not all(0 <= qs <= 1 for qs in q_arr): + raise ValueError(msg) return q_arr