Skip to content

Commit 7e25af8

Browse files
PERF: Fix quantile perf regression (#35101)
1 parent a6b5e16 commit 7e25af8

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

pandas/util/_validators.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,13 @@ def validate_percentile(q: Union[float, Iterable[float]]) -> np.ndarray:
371371
ValueError if percentiles are not in given interval([0, 1]).
372372
"""
373373
q_arr = np.asarray(q)
374-
msg = (
375-
"percentiles should all be in the interval [0, 1]."
376-
f"Try {q_arr / 100.0} instead."
377-
)
374+
# Don't change this to an f-string. The string formatting
375+
# is too expensive for cases where we don't need it.
376+
msg = "percentiles should all be in the interval [0, 1]. Try {} instead."
378377
if q_arr.ndim == 0:
379378
if not 0 <= q_arr <= 1:
380-
raise ValueError(msg)
379+
raise ValueError(msg.format(q_arr / 100.0))
381380
else:
382381
if not all(0 <= qs <= 1 for qs in q_arr):
383-
raise ValueError(msg)
382+
raise ValueError(msg.format(q_arr / 100.0))
384383
return q_arr

0 commit comments

Comments
 (0)