From b4ce57534c46a16cf7d8efcc2cb67ea8ec1c3ac6 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Thu, 2 Jul 2020 15:43:00 -0500 Subject: [PATCH 1/2] PERF: Fix quantile perf regression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes https://github.com/pandas-dev/pandas/issues/35049 ```pyhon 591 µs ± 29.5 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) 440 µs ± 22.8 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) ``` --- pandas/util/_validators.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pandas/util/_validators.py b/pandas/util/_validators.py index bb6c6de441558..0db610aa7fc22 100644 --- a/pandas/util/_validators.py +++ b/pandas/util/_validators.py @@ -371,14 +371,13 @@ def validate_percentile(q: Union[float, Iterable[float]]) -> np.ndarray: ValueError if percentiles are not in given interval([0, 1]). """ q_arr = np.asarray(q) - msg = ( - "percentiles should all be in the interval [0, 1]." - f"Try {q_arr / 100.0} instead." - ) + # 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." if q_arr.ndim == 0: if not 0 <= q_arr <= 1: - raise ValueError(msg) + raise ValueError(msg.format(q_arr / 100.0)) else: if not all(0 <= qs <= 1 for qs in q_arr): - raise ValueError(msg) + raise ValueError(msg.format(q_arr / 100.0)) return q_arr From 408c2dba05333eb5ebb7ebbaae651ec663ceb2f5 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Fri, 3 Jul 2020 06:22:08 -0500 Subject: [PATCH 2/2] Update _validators.py --- pandas/util/_validators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/util/_validators.py b/pandas/util/_validators.py index 0db610aa7fc22..fa7201a5188a5 100644 --- a/pandas/util/_validators.py +++ b/pandas/util/_validators.py @@ -373,7 +373,7 @@ def validate_percentile(q: Union[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]. Try {} instead." if q_arr.ndim == 0: if not 0 <= q_arr <= 1: raise ValueError(msg.format(q_arr / 100.0))