From b3c0960a54c81a26bd07912dda96db9e356b34d1 Mon Sep 17 00:00:00 2001 From: Matteo Raso <33975162+MatteoRaso@users.noreply.github.com> Date: Thu, 8 Dec 2022 07:01:59 -0500 Subject: 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 --- numpy/lib/nanfunctions.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'numpy/lib/nanfunctions.py') diff --git a/numpy/lib/nanfunctions.py b/numpy/lib/nanfunctions.py index ae2dfa165..786d2021e 100644 --- a/numpy/lib/nanfunctions.py +++ b/numpy/lib/nanfunctions.py @@ -1373,6 +1373,9 @@ def nanpercentile( method, interpolation, "nanpercentile") 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.0) # undo any decay that the ufunc performed (see gh-13105) q = np.asanyarray(q) @@ -1527,11 +1530,15 @@ def nanquantile( The American Statistician, 50(4), pp. 361-365, 1996 """ + if interpolation is not None: method = function_base._check_interpolation_as_method( method, interpolation, "nanquantile") 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 function_base._quantile_is_valid(q): raise ValueError("Quantiles must be in the range [0, 1]") -- cgit v1.2.1