Skip to content

Commit edd5b01

Browse files
committed
Fixed warnings
1 parent 1e26a75 commit edd5b01

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

pandas/core/frame.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -11129,11 +11129,27 @@ def cummax(self, axis: Axis | None = None, skipna: bool = True, *args, **kwargs)
1112911129
return NDFrame.cummax(self, axis, skipna, *args, **kwargs)
1113011130

1113111131
@doc(make_doc("cumsum", ndim=2))
11132-
def cumsum(self, axis: Axis | None = None, skipna: bool = True, *args, **kwargs):
11132+
def cumsum(
11133+
self,
11134+
axis: Axis | None = None,
11135+
numeric_only: bool = False,
11136+
skipna: bool = True,
11137+
*args,
11138+
**kwargs,
11139+
):
11140+
self._get_numeric_data() if numeric_only else self
1113311141
return NDFrame.cumsum(self, axis, skipna, *args, **kwargs)
1113411142

1113511143
@doc(make_doc("cumprod", 2))
11136-
def cumprod(self, axis: Axis | None = None, skipna: bool = True, *args, **kwargs):
11144+
def cumprod(
11145+
self,
11146+
axis: Axis | None = None,
11147+
numeric_only: bool = False,
11148+
skipna: bool = True,
11149+
*args,
11150+
**kwargs,
11151+
):
11152+
self._get_numeric_data() if numeric_only else self
1113711153
return NDFrame.cumprod(self, axis, skipna, *args, **kwargs)
1113811154

1113911155
def nunique(self, axis: Axis = 0, dropna: bool = True) -> Series:

pandas/core/generic.py

+1
Original file line numberDiff line numberDiff line change
@@ -11578,6 +11578,7 @@ def _accum_func(
1157811578
*args,
1157911579
**kwargs,
1158011580
):
11581+
skipna = nv.validate_cum_func_with_skipna(skipna, args, kwargs, name)
1158111582
if name not in ["cumprod", "cumsum"]:
1158211583
skipna = nv.validate_cum_func_with_skipna(skipna, args, kwargs, name)
1158311584
if axis is None:

pandas/tests/groupby/test_api.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ def test_frame_consistency(groupby_func):
184184
exclude_expected = {"skipna", "args"}
185185
exclude_result = {"numeric_only"}
186186
elif groupby_func in ("cumprod", "cumsum"):
187-
exclude_expected = {"args", "kwargs"}
188-
exclude_result = {"numeric_only"}
187+
exclude_expected = {"skipna", "numeric_only"}
189188
elif groupby_func in ("pct_change",):
190189
exclude_expected = {"kwargs"}
191190
exclude_result = {"axis"}
@@ -243,8 +242,7 @@ def test_series_consistency(request, groupby_func):
243242
exclude_expected = {"skipna", "args"}
244243
exclude_result = {"numeric_only"}
245244
elif groupby_func in ("cumprod", "cumsum"):
246-
exclude_expected = {"args", "kwargs"}
247-
exclude_result = {"numeric_only"}
245+
exclude_expected = {"skipna"}
248246
elif groupby_func in ("pct_change",):
249247
exclude_expected = {"kwargs"}
250248
exclude_result = {"axis"}

pandas/tests/groupby/test_function.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,9 @@ def test_axis1_numeric_only(request, groupby_func, numeric_only):
565565
warn_msg = f"DataFrameGroupBy.{groupby_func} with axis=1 is deprecated"
566566
if numeric_only is not None and groupby_func in no_args:
567567
msg = "got an unexpected keyword argument 'numeric_only'"
568-
with pytest.raises(TypeError, match=msg):
569-
method(*args, **kwargs)
568+
if groupby_func in ["cumprod", "cumsum"]:
569+
with tm.assert_produces_warning(FutureWarning, match=warn_msg):
570+
method(*args, **kwargs)
570571
elif groupby_func not in has_axis:
571572
msg = "got an unexpected keyword argument 'axis'"
572573
with pytest.raises(TypeError, match=msg):

pandas/tests/series/test_api.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ def test_series_datetimelike_attribute_access_invalid(self):
231231
("cummax", False),
232232
("shift", False),
233233
("diff", False),
234-
("cumsum", True),
234+
("cumsum", False),
235235
("cummin", False),
236-
("cumprod", True),
236+
("cumprod", False),
237237
("fillna", False),
238238
("ffill", False),
239239
("pad", False),
@@ -276,7 +276,7 @@ def test_numeric_only(self, kernel, has_numeric_only, dtype):
276276
)
277277
with pytest.raises(TypeError, match=msg):
278278
method(*args, numeric_only=True)
279-
elif dtype is object and kernel not in ["cumprod", "cumsum"]:
279+
elif dtype is object:
280280
msg = f"Series.{kernel} does not allow numeric_only=True with non-numeric"
281281
with pytest.raises(TypeError, match=msg):
282282
method(*args, numeric_only=True)

0 commit comments

Comments
 (0)