Skip to content

Commit ce581e6

Browse files
BUG: Remove "Mean of empty slice" warning in nanmedian (#58107)
* Filter Mean of empty slice warning in nanmedian When the array is full of NAs, it ends up in get_median which issues that warning. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 33af3b8 commit ce581e6

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pandas/core/nanops.py

+5
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,10 @@ def nanmedian(values, *, axis: AxisInt | None = None, skipna: bool = True, mask=
745745
>>> s = pd.Series([1, np.nan, 2, 2])
746746
>>> nanops.nanmedian(s.values)
747747
2.0
748+
749+
>>> s = pd.Series([np.nan, np.nan, np.nan])
750+
>>> nanops.nanmedian(s.values)
751+
nan
748752
"""
749753
# for floats without mask, the data already uses NaN as missing value
750754
# indicator, and `mask` will be calculated from that below -> in those
@@ -763,6 +767,7 @@ def get_median(x, _mask=None):
763767
warnings.filterwarnings(
764768
"ignore", "All-NaN slice encountered", RuntimeWarning
765769
)
770+
warnings.filterwarnings("ignore", "Mean of empty slice", RuntimeWarning)
766771
res = np.nanmedian(x[_mask])
767772
return res
768773

0 commit comments

Comments
 (0)