diff options
author | Julian Taylor <jtaylor.debian@googlemail.com> | 2017-02-27 14:10:13 +0100 |
---|---|---|
committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2017-02-27 16:43:42 +0100 |
commit | 05aa44d53f4f9528847a0c014fe4bda5caa5fd3d (patch) | |
tree | 441b603859c485f386ee9b9adb9042b947e6ca54 /numpy/ma/extras.py | |
parent | ad8afe82e7b7643607a348c0e02b45c9131c6a06 (diff) | |
download | numpy-05aa44d53f4f9528847a0c014fe4bda5caa5fd3d.tar.gz |
BUG: fix ma.median for empty ndarrays
return nan as it did in 1.11 and same as normal median.
closes gh-8703
Diffstat (limited to 'numpy/ma/extras.py')
-rw-r--r-- | numpy/ma/extras.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py index 7149b525b..697565251 100644 --- a/numpy/ma/extras.py +++ b/numpy/ma/extras.py @@ -717,6 +717,13 @@ def _median(a, axis=None, out=None, overwrite_input=False): else: axis = normalize_axis_index(axis, asorted.ndim) + if asorted.shape[axis] == 0: + # for empty axis integer indices fail so use slicing to get same result + # as median (which is mean of empty slice = nan) + indexer = [slice(None)] * asorted.ndim + indexer[axis] = slice(0, 0) + return np.ma.mean(asorted[indexer], axis=axis, out=out) + if asorted.ndim == 1: counts = count(asorted) idx, odd = divmod(count(asorted), 2) |