diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 2af9e09d1c713..83626a42134d6 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -937,7 +937,13 @@ def asfreq(self, fill_value=None): """ return self._upsample("asfreq", fill_value=fill_value) - def std(self, ddof=1, numeric_only: bool = False, *args, **kwargs): + def std( + self, + ddof=1, + numeric_only: bool | lib.NoDefault = lib.no_default, + *args, + **kwargs, + ): """ Compute standard deviation of groups, excluding missing values. @@ -958,7 +964,13 @@ def std(self, ddof=1, numeric_only: bool = False, *args, **kwargs): nv.validate_resampler_func("std", args, kwargs) return self._downsample("std", ddof=ddof, numeric_only=numeric_only) - def var(self, ddof=1, numeric_only: bool = False, *args, **kwargs): + def var( + self, + ddof=1, + numeric_only: bool | lib.NoDefault = lib.no_default, + *args, + **kwargs, + ): """ Compute variance of groups, excluding missing values. diff --git a/pandas/tests/resample/test_resample_api.py b/pandas/tests/resample/test_resample_api.py index 2d74b703b9bb1..c5cd777962df3 100644 --- a/pandas/tests/resample/test_resample_api.py +++ b/pandas/tests/resample/test_resample_api.py @@ -859,6 +859,10 @@ def test_frame_downsample_method(method, numeric_only, expected_data): expected_index = date_range("2018-12-31", periods=1, freq="Y") df = DataFrame({"cat": ["cat_1", "cat_2"], "num": [5, 20]}, index=index) resampled = df.resample("Y") + if numeric_only is lib.no_default: + kwargs = {} + else: + kwargs = {"numeric_only": numeric_only} func = getattr(resampled, method) if numeric_only is lib.no_default and method not in ( @@ -882,9 +886,9 @@ def test_frame_downsample_method(method, numeric_only, expected_data): if isinstance(expected_data, str): klass = TypeError if method == "var" else ValueError with pytest.raises(klass, match=expected_data): - _ = func(numeric_only=numeric_only) + _ = func(**kwargs) else: - result = func(numeric_only=numeric_only) + result = func(**kwargs) expected = DataFrame(expected_data, index=expected_index) tm.assert_frame_equal(result, expected)