8000 REF: avoid special case in DTA/TDA.median, flesh out tests by jbrockmendel · Pull Request #37423 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

REF: avoid special case in DTA/TDA.median, flesh out tests #37423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 31, 2020
Prev Previous commit
Next Next commit
suppress warning
  • Loading branch information
jbrockmendel committed Oct 26, 2020
commit c52b0bce6f4f38aa1e1eccd1d6142ee1cb8f526b
13 changes: 11 additions & 2 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import itertools
import operator
from typing import Any, Optional, Tuple, Union, cast
import warnings

import numpy as np

Expand Down Expand Up @@ -643,7 +644,11 @@ def get_median(x):
mask = notna(x)
if not skipna and not mask.all():
return np.nan
return np.nanmedian(x[mask])
with warnings.catch_warnings():
# Suppress RuntimeWarning about All-NaN slice
warnings.filterwarnings("ignore", "All-NaN slice encountered")
res = np.nanmedian(x[mask])
return res

values, mask, dtype, _, _ = _get_values(values, skipna, mask=mask)
if not is_float_dtype(values.dtype):
Expand Down Expand Up @@ -671,7 +676,11 @@ def get_median(x):
)

# fastpath for the skipna case
return _wrap_results(np.nanmedian(values, axis), dtype)
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"
Expand Down
0