From f2cfb496c60770302dcfd9fa78355dfc6cdad9e0 Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 6 Nov 2020 13:16:31 -0800 Subject: [PATCH] CLN: only call _wrap_results one place in nanmedian --- pandas/core/nanops.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index 8e917bb770247..5da8bd300433e 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -681,26 +681,26 @@ def get_median(x): # there's a non-empty array to apply over otherwise numpy raises if notempty: if not skipna: - return _wrap_results( - np.apply_along_axis(get_median, axis, values), dtype - ) + res = np.apply_along_axis(get_median, axis, values) + + else: + # fastpath for the skipna case + with warnings.catch_warnings(): + # Suppress RuntimeWarning about All-NaN slice + warnings.filterwarnings("ignore", "All-NaN slice encountered") + res = np.nanmedian(values, axis) - # fastpath for the skipna case - with warnings.catch_warnings(): - # Suppress RuntimeWarning about All-NaN slice - warnings.filterwarnings("ignore", "All-NaN slice encountered") - res = np.nanmedian(values, axis) - return _wrap_results(res, dtype) - - # must return the correct shape, but median is not defined for the - # empty set so return nans of shape "everything but the passed axis" - # since "axis" is where the reduction would occur if we had a nonempty - # array - ret = get_empty_reduction_result(values.shape, axis, np.float_, np.nan) - return _wrap_results(ret, dtype) - - # otherwise return a scalar value - return _wrap_results(get_median(values) if notempty else np.nan, dtype) + else: + # must return the correct shape, but median is not defined for the + # empty set so return nans of shape "everything but the passed axis" + # since "axis" is where the reduction would occur if we had a nonempty + # array + res = get_empty_reduction_result(values.shape, axis, np.float_, np.nan) + + else: + # otherwise return a scalar value + res = get_median(values) if notempty else np.nan + return _wrap_results(res, dtype) def get_empty_reduction_result(