From 9a23f16b67958205468f7f5c4e0966f393558d9a Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Tue, 23 Apr 2019 01:55:21 -0700 Subject: ENH: Add support for Fraction to percentile and quantile With true division available, using `.0` to convert integers to floats offers no value, and harms compatibility with precise rational types. --- numpy/lib/function_base.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'numpy/lib/function_base.py') diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 2e82fa075..cab680751 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3706,7 +3706,8 @@ def percentile(a, q, axis=None, out=None, plt.show() """ - q = np.true_divide(q, 100.0) # handles the asarray for us too + 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): raise ValueError("Percentiles must be in the range [0, 100]") return _quantile_unchecked( @@ -3924,7 +3925,7 @@ def _quantile_ureduce_func(a, q, axis=None, out=None, overwrite_input=False, indices_above = concatenate((indices_above, [-1])) weights_above = indices - indices_below - weights_below = 1.0 - weights_above + weights_below = 1 - weights_above weights_shape = [1, ] * ap.ndim weights_shape[axis] = len(indices) -- cgit v1.2.1 From d7de4ad70d6794b36e4789e4f6146a884113bd66 Mon Sep 17 00:00:00 2001 From: ayir Date: Wed, 10 Apr 2019 17:00:25 +0200 Subject: ENH: add clearer error message for diff(0-d) --- numpy/lib/function_base.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'numpy/lib/function_base.py') diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index fb40ef927..7a405b382 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1235,6 +1235,8 @@ def diff(a, n=1, axis=-1, prepend=np._NoValue, append=np._NoValue): a = asanyarray(a) nd = a.ndim + if nd == 0: + raise ValueError("diff requires input that is at least one dimensional") axis = normalize_axis_index(axis, nd) combined = [] -- cgit v1.2.1