MCPcopy
hub / github.com/pandas-dev/pandas / validate_percentile

Function validate_percentile

pandas/util/_validators.py:339–369  ·  view source on GitHub ↗

Validate percentiles (used by describe and quantile). This function checks if the given float or iterable of floats is a valid percentile otherwise raises a ValueError. Parameters ---------- q: float or iterable of floats A single percentile or an iterable of perce

(q: float | Iterable[float])

Source from the content-addressed store, hash-verified

337
338
339def validate_percentile(q: float | Iterable[float]) -> np.ndarray:
340 """
341 Validate percentiles (used by describe and quantile).
342
343 This function checks if the given float or iterable of floats is a valid percentile
344 otherwise raises a ValueError.
345
346 Parameters
347 ----------
348 q: float or iterable of floats
349 A single percentile or an iterable of percentiles.
350
351 Returns
352 -------
353 ndarray
354 An ndarray of the percentiles if valid.
355
356 Raises
357 ------
358 ValueError if percentiles are not in given interval([0, 1]).
359 """
360 q_arr = np.asarray(q)
361 # Don't change this to an f-string. The string formatting
362 # is too expensive for cases where we don't need it.
363 msg = "percentiles should all be in the interval [0, 1]"
364 if q_arr.ndim == 0:
365 if not 0 <= q_arr <= 1:
366 raise ValueError(msg)
367 elif not all(0 <= qs <= 1 for qs in q_arr):
368 raise ValueError(msg)
369 return q_arr
370
371
372@overload

Callers 3

quantileMethod · 0.90
quantileMethod · 0.90
_refine_percentilesFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected