Skip to content

BUG: Remove "Mean of empty slice" warning in nanmedian #58107

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 2 commits into from
Apr 1, 2024
Merged
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,10 @@ def nanmedian(values, *, axis: AxisInt | None = None, skipna: bool = True, mask=
>>> s = pd.Series([1, np.nan, 2, 2])
>>> nanops.nanmedian(s.values)
2.0

>>> s = pd.Series([np.nan, np.nan, np.nan])
>>> nanops.nanmedian(s.values)
nan
"""
# for floats without mask, the data already uses NaN as missing value
# indicator, and `mask` will be calculated from that below -> in those
Expand All @@ -763,6 +767,7 @@ def get_median(x, _mask=None):
warnings.filterwarnings(
"ignore", "All-NaN slice encountered", RuntimeWarning
)
warnings.filterwarnings("ignore", "Mean of empty slice", RuntimeWarning)
res = np.nanmedian(x[_mask])
return res

Expand Down