@@ -3714,16 +3714,15 @@ def _median(a, axis=None, out=None, overwrite_input=False):
37143714 indexer [axis ] = slice (index - 1 , index + 1 )
37153715 indexer = tuple (indexer )
37163716
3717+ # Use mean in both odd and even case to coerce data type,
3718+ # using out array if needed.
3719+ rout = mean (part [indexer ], axis = axis , out = out )
37173720 # Check if the array contains any nan's
37183721 if np .issubdtype (a .dtype , np .inexact ) and sz > 0 :
3719- # warn and return nans like mean would
3720- rout = mean (part [indexer ], axis = axis , out = out )
3721- return np .lib .utils ._median_nancheck (part , rout , axis , out )
3722- else :
3723- # if there are no nans
3724- # Use mean in odd and even case to coerce data type
3725- # and check, use out array.
3726- return mean (part [indexer ], axis = axis , out = out )
3722+ # If nans are possible, warn and replace by nans like mean would.
3723+ rout = np .lib .utils ._median_nancheck (part , rout , axis )
3724+
3725+ return rout
37273726
37283727
37293728def _percentile_dispatcher (a , q , axis = None , out = None , overwrite_input = None ,
0 commit comments