8000 REF: implement _wrap_reduction_result by jbrockmendel · Pull Request #37660 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

REF: implement _wrap_reduction_result #37660

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 18 commits into from
Nov 8, 2020
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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