summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
authorKevin Sheppard <bashtage@users.noreply.github.com>2021-04-22 14:35:43 +0100
committerGitHub <noreply@github.com>2021-04-22 08:35:43 -0500
commit341316d5158477b06f877db60049b0995ab78128 (patch)
tree3cabe19b30eaed52551ba58a7dfa4945f688fda6 /numpy/lib/function_base.py
parentf048051926bdc1f145b4e6a9516b0ee55b5d1e8e (diff)
downloadnumpy-341316d5158477b06f877db60049b0995ab78128.tar.gz
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
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py5
1 files changed, 2 insertions, 3 deletions
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