From 05aa44d53f4f9528847a0c014fe4bda5caa5fd3d Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Mon, 27 Feb 2017 14:10:13 +0100 Subject: BUG: fix ma.median for empty ndarrays return nan as it did in 1.11 and same as normal median. closes gh-8703 --- numpy/ma/extras.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'numpy/ma/extras.py') 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) -- cgit v1.2.1