summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
authorMatteo Raso <33975162+MatteoRaso@users.noreply.github.com>2022-12-08 07:01:59 -0500
committerGitHub <noreply@github.com>2022-12-08 13:01:59 +0100
commitb3c0960a54c81a26bd07912dda96db9e356b34d1 (patch)
tree2eca2dbef14e50ddc3340c20413c60e011c62ff2 /numpy/lib/function_base.py
parent6f9237e91ef26df62d40161458178f972db7ce26 (diff)
downloadnumpy-b3c0960a54c81a26bd07912dda96db9e356b34d1.tar.gz
BUG: Quantile function on complex number now throws an error (#22652) (#22703)
Since percentile is more or less identical to quantile, I also made it throw an error if it receives a complex input. I also made nanquantile and nanpercentile throw errors as well. * Made the changes recommended by seberg * Fixed a test for PR 22703 * Fixed tests for quantile * Shortened some more lines * Fixup more lines Co-authored-by: Sebastian Berg <sebastianb@nvidia.com>
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 35a3b3543..9989e9759 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -3934,7 +3934,7 @@ def percentile(a,
Parameters
----------
- a : array_like
+ a : array_like of real numbers
Input array or object that can be converted to an array.
q : array_like of float
Percentile or sequence of percentiles to compute, which must be between
@@ -4198,6 +4198,11 @@ def percentile(a,
if interpolation is not None:
method = _check_interpolation_as_method(
method, interpolation, "percentile")
+
+ a = np.asanyarray(a)
+ if a.dtype.kind == "c":
+ raise TypeError("a must be an array of real numbers")
+
q = np.true_divide(q, 100)
q = asanyarray(q) # undo any decay that the ufunc performed (see gh-13105)
if not _quantile_is_valid(q):
@@ -4228,7 +4233,7 @@ def quantile(a,
Parameters
----------
- a : array_like
+ a : array_like of real numbers
Input array or object that can be converted to an array.
q : array_like of float
Quantile or sequence of quantiles to compute, which must be between
@@ -4455,6 +4460,10 @@ def quantile(a,
method = _check_interpolation_as_method(
method, interpolation, "quantile")
+ a = np.asanyarray(a)
+ if a.dtype.kind == "c":
+ raise TypeError("a must be an array of real numbers")
+
q = np.asanyarray(q)
if not _quantile_is_valid(q):
raise ValueError("Quantiles must be in the range [0, 1]")