Function
_percentile
(values: Iterable[float], p: float)
Source from the content-addressed store, hash-verified
| 234 | |
| 235 | |
| 236 | def _percentile(values: Iterable[float], p: float) -> float | None: |
| 237 | sample = sorted(v for v in values if v is not None) |
| 238 | if not sample: |
| 239 | return None |
| 240 | if len(sample) == 1: |
| 241 | return sample[0] |
| 242 | k = (len(sample) - 1) * p |
| 243 | lo = math.floor(k) |
| 244 | hi = math.ceil(k) |
| 245 | if lo == hi: |
| 246 | return sample[int(k)] |
| 247 | return sample[lo] + (sample[hi] - sample[lo]) * (k - lo) |
| 248 | |
| 249 | |
| 250 | def summarize( |
Tested by
no test coverage detected