summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index d875a00ae..e33d55056 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -3714,16 +3714,15 @@ def _median(a, axis=None, out=None, overwrite_input=False):
indexer[axis] = slice(index-1, index+1)
indexer = tuple(indexer)
+ # Use mean in both odd and even case to coerce data type,
+ # using out array if needed.
+ rout = mean(part[indexer], axis=axis, out=out)
# Check if the array contains any nan's
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)
- 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
- # and check, use out array.
- return mean(part[indexer], axis=axis, out=out)
+ # If nans are possible, warn and replace by nans like mean would.
+ rout = np.lib.utils._median_nancheck(part, rout, axis)
+
+ return rout
def _percentile_dispatcher(a, q, axis=None, out=None, overwrite_input=None,