From ba6fdacd434a70496cfc61240e34045b6a6550a7 Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Sun, 11 Dec 2016 20:35:50 +0100 Subject: [PATCH] BUG: fix nanpercentile not returning scalar with axis argument Closes gh-8220 --- numpy/lib/nanfunctions.py | 2 +- numpy/lib/tests/test_nanfunctions.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/numpy/lib/nanfunctions.py b/numpy/lib/nanfunctions.py index c024055bae0b..24472dfcd910 100644 --- a/numpy/lib/nanfunctions.py +++ b/numpy/lib/nanfunctions.py @@ -1134,7 +1134,7 @@ def _nanpercentile(a, q, axis=None, out=None, overwrite_input=False, See nanpercentile for parameter usage """ - if axis is None: + if axis is None or a.ndim == 1: part = a.ravel() result = _nanpercentile1d(part, q, overwrite_input, interpolation) else: diff --git a/numpy/lib/tests/test_nanfunctions.py b/numpy/lib/tests/test_nanfunctions.py index 06c0953b5df7..3fde51a73092 100644 --- a/numpy/lib/tests/test_nanfunctions.py +++ b/numpy/lib/tests/test_nanfunctions.py @@ -805,7 +805,11 @@ def test_empty(self): assert_(len(w) == 0) def test_scalar(self): - assert_(np.nanpercentile(0., 100) == 0.) + assert_equal(np.nanpercentile(0., 100), 0.) + a = np.arange(6) + r = np.nanpercentile(a, 50, axis=0) + assert_equal(r, 2.5) + assert_(np.isscalar(r)) def test_extended_axis_invalid(self): d = np.ones((3, 5, 7, 11))