diff options
author | Julian Taylor <jtaylor.debian@googlemail.com> | 2016-12-06 00:37:53 +0100 |
---|---|---|
committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2016-12-12 23:19:06 +0100 |
commit | ff4758ff8432077c06cb580b97c6080f9b312c5a (patch) | |
tree | a40b77c06a1446f053f405a31bf0bcff91d3d8eb /numpy/lib/function_base.py | |
parent | e00b9587052248486a9bf66c2ce95638c0d9817f (diff) | |
download | numpy-ff4758ff8432077c06cb580b97c6080f9b312c5a.tar.gz |
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.
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 18 |
1 files changed, 1 insertions, 17 deletions
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 |