From 341316d5158477b06f877db60049b0995ab78128 Mon Sep 17 00:00:00 2001 From: Kevin Sheppard Date: Thu, 22 Apr 2021 14:35:43 +0100 Subject: BUG: Prevent nan being used in percentile (gh-18831) Reject NaN as a percentile/quantile value. Previously NaNs could pass the range check `0 <= q <= 1`. closes #18830 --- numpy/lib/function_base.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'numpy/lib/function_base.py') diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index af5a6e45c..0bb41c270 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3957,11 +3957,10 @@ def _quantile_is_valid(q): # avoid expensive reductions, relevant for arrays with < O(1000) elements if q.ndim == 1 and q.size < 10: for i in range(q.size): - if q[i] < 0.0 or q[i] > 1.0: + if not (0.0 <= q[i] <= 1.0): return False else: - # faster than any() - if np.count_nonzero(q < 0.0) or np.count_nonzero(q > 1.0): + if not (np.all(0 <= q) and np.all(q <= 1)): return False return True -- cgit v1.2.1