From ff4758ff8432077c06cb580b97c6080f9b312c5a Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Tue, 6 Dec 2016 00:37:53 +0100 Subject: BUG: handle unmasked NaN in ma.median like normal median This requires to base masked median on sort(endwith=False) as we need to distinguish Inf and NaN. Using Inf as filler element of the sort does not work as then the mask is not guaranteed to be at the end. Closes gh-8340 Also fixed 1d ma.median not handling np.inf correctly, the nd variant was ok. --- numpy/lib/function_base.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'numpy/lib/function_base.py') diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 352512513..172e9a322 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3982,23 +3982,7 @@ def _median(a, axis=None, out=None, overwrite_input=False): if np.issubdtype(a.dtype, np.inexact) and sz > 0: # warn and return nans like mean would rout = mean(part[indexer], axis=axis, out=out) - part = np.rollaxis(part, axis, part.ndim) - n = np.isnan(part[..., -1]) - if rout.ndim == 0: - if n == True: - warnings.warn("Invalid value encountered in median", - RuntimeWarning, stacklevel=3) - if out is not None: - out[...] = a.dtype.type(np.nan) - rout = out - else: - rout = a.dtype.type(np.nan) - elif np.count_nonzero(n.ravel()) > 0: - warnings.warn("Invalid value encountered in median for" + - " %d results" % np.count_nonzero(n.ravel()), - RuntimeWarning, stacklevel=3) - rout[n] = np.nan - return rout + return np.lib.utils._median_nancheck(part, rout, axis, out) else: # if there are no nans # Use mean in odd and even case to coerce data type -- cgit v1.2.1