From 83dd67c24d6bb8c181a07aa4428c318ef23265f1 Mon Sep 17 00:00:00 2001 From: Sebastian Correa <43179146+sebastian-correa@users.noreply.github.com> Date: Mon, 1 Apr 2024 14:14:03 -0300 Subject: [PATCH 1/2] 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. --- pandas/core/nanops.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index a124e8679ae8e..d34781ee7f4c5 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -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 @@ -763,6 +767,9 @@ 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 From 7eb1c9c62fd2ba1868effe1059151497fa43fa8d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 20:50:58 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pandas/core/nanops.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index d34781ee7f4c5..2bc5f031ce69d 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -767,9 +767,7 @@ def get_median(x, _mask=None): warnings.filterwarnings( "ignore", "All-NaN slice encountered", RuntimeWarning ) - warnings.filterwarnings( - "ignore", "Mean of empty slice", RuntimeWarning - ) + warnings.filterwarnings("ignore", "Mean of empty slice", RuntimeWarning) res = np.nanmedian(x[_mask]) return res