Skip to content

Commit 0a6be38

Browse files
authored
BUG: Correct numeric_only default for resample var and std (#47749)
1 parent ad7dcef commit 0a6be38

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

pandas/core/resample.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,13 @@ def asfreq(self, fill_value=None):
937937
"""
938938
return self._upsample("asfreq", fill_value=fill_value)
939939

940-
def std(self, ddof=1, numeric_only: bool = False, *args, **kwargs):
940+
def std(
941+
self,
942+
ddof=1,
943+
numeric_only: bool | lib.NoDefault = lib.no_default,
944+
*args,
945+
**kwargs,
946+
):
941947
"""
942948
Compute standard deviation of groups, excluding missing values.
943949
@@ -958,7 +964,13 @@ def std(self, ddof=1, numeric_only: bool = False, *args, **kwargs):
958964
nv.validate_resampler_func("std", args, kwargs)
959965
return self._downsample("std", ddof=ddof, numeric_only=numeric_only)
960966

961-
def var(self, ddof=1, numeric_only: bool = False, *args, **kwargs):
967+
def var(
968+
self,
969+
ddof=1,
970+
numeric_only: bool | lib.NoDefault = lib.no_default,
971+
*args,
972+
**kwargs,
973+
):
962974
"""
963975
Compute variance of groups, excluding missing values.
964976

pandas/tests/resample/test_resample_api.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,10 @@ def test_frame_downsample_method(method, numeric_only, expected_data):
859859
expected_index = date_range("2018-12-31", periods=1, freq="Y")
860860
df = DataFrame({"cat": ["cat_1", "cat_2"], "num": [5, 20]}, index=index)
861861
resampled = df.resample("Y")
862+
if numeric_only is lib.no_default:
863+
kwargs = {}
864+
else:
865+
kwargs = {"numeric_only": numeric_only}
862866

863867
func = getattr(resampled, method)
864868
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):
882886
if isinstance(expected_data, str):
883887
klass = TypeError if method == "var" else ValueError
884888
with pytest.raises(klass, match=expected_data):
885-
_ = func(numeric_only=numeric_only)
889+
_ = func(**kwargs)
886890
else:
887-
result = func(numeric_only=numeric_only)
891+
result = func(**kwargs)
888892
expected = DataFrame(expected_data, index=expected_index)
889893
tm.assert_frame_equal(result, expected)
890894

0 commit comments

Comments
 (0)