Skip to content

Commit a5be3bd

Browse files
committed
Fixed warnings and modified tests
1 parent e0f3b1d commit a5be3bd

File tree

6 files changed

+54
-25
lines changed

6 files changed

+54
-25
lines changed

pandas/core/frame.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -11129,11 +11129,23 @@ 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+
skipna: bool = True,
11136+
*args,
11137+
**kwargs,
11138+
):
1113311139
return NDFrame.cumsum(self, axis, skipna, *args, **kwargs)
1113411140

1113511141
@doc(make_doc("cumprod", 2))
11136-
def cumprod(self, axis: Axis | None = None, skipna: bool = True, *args, **kwargs):
11142+
def cumprod(
11143+
self,
11144+
axis: Axis | None = None,
11145+
skipna: bool = True,
11146+
*args,
11147+
**kwargs,
11148+
):
1113711149
return NDFrame.cumprod(self, axis, skipna, *args, **kwargs)
1113811150

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

pandas/core/generic.py

-1
Original file line numberDiff line numberDiff line change
@@ -11578,7 +11578,6 @@ def _accum_func(
1157811578
*args,
1157911579
**kwargs,
1158011580
):
11581-
skipna = nv.validate_cum_func_with_skipna(skipna, args, kwargs, name)
1158211581
if axis is None:
1158311582
axis = 0
1158411583
else:

pandas/core/groupby/groupby.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -4573,6 +4573,7 @@ def cumprod(
45734573
axis: Axis | lib.NoDefault = lib.no_default,
45744574
numeric_only: bool = False,
45754575
skipna: bool = True,
4576+
**kwargs,
45764577
) -> NDFrameT:
45774578
"""
45784579
Cumulative product for each group.
@@ -4633,11 +4634,13 @@ def cumprod(
46334634
axis = 0
46344635

46354636
if axis != 0:
4636-
f = lambda x: x.cumprod(axis=axis, numeric_only=numeric_only, skipna=skipna)
4637+
f = lambda x: x.cumprod(
4638+
axis=axis, numeric_only=numeric_only, skipna=skipna, **kwargs
4639+
)
46374640
return self._python_apply_general(f, self._selected_obj, is_transform=True)
46384641

46394642
return self._cython_transform(
4640-
"cumprod", numeric_only=numeric_only, skipna=skipna
4643+
"cumprod", numeric_only=numeric_only, skipna=skipna, **kwargs
46414644
)
46424645

46434646
@final
@@ -4648,6 +4651,7 @@ def cumsum(
46484651
axis: Axis | lib.NoDefault = lib.no_default,
46494652
numeric_only: bool = False,
46504653
skipna: bool = True,
4654+
**kwargs,
46514655
) -> NDFrameT:
46524656
"""
46534657
Cumulative sum for each group.
@@ -4708,11 +4712,13 @@ def cumsum(
47084712
axis = 0
47094713

47104714
if axis != 0:
4711-
f = lambda x: x.cumsum(axis=axis, numeric_only=numeric_only, skipna=skipna)
4715+
f = lambda x: x.cumsum(
4716+
axis=axis, numeric_only=numeric_only, skipna=skipna, **kwargs
4717+
)
47124718
return self._python_apply_general(f, self._selected_obj, is_transform=True)
47134719

47144720
return self._cython_transform(
4715-
"cumsum", numeric_only=numeric_only, skipna=skipna
4721+
"cumsum", numeric_only=numeric_only, skipna=skipna, **kwargs
47164722
)
47174723

47184724
@final

pandas/core/series.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -6204,9 +6204,23 @@ def cummax(self, axis: Axis | None = None, skipna: bool = True, *args, **kwargs)
62046204
return NDFrame.cummax(self, axis, skipna, *args, **kwargs)
62056205

62066206
@doc(make_doc("cumsum", ndim=1))
6207-
def cumsum(self, axis: Axis | None = None, skipna: bool = True, *args, **kwargs):
6208-
return NDFrame.cumsum(self, axis, skipna, *args, **kwargs)
6207+
def cumsum(
6208+
self,
6209+
axis: Axis | None = None,
6210+
numeric_only: bool = False,
6211+
skipna: bool = True,
6212+
*args,
6213+
**kwargs,
6214+
):
6215+
return NDFrame.cumsum(self, axis, numeric_only, skipna, *args, **kwargs)
62096216

62106217
@doc(make_doc("cumprod", 1))
6211-
def cumprod(self, axis: Axis | None = None, skipna: bool = True, *args, **kwargs):
6212-
return NDFrame.cumprod(self, axis, skipna, *args, **kwargs)
6218+
def cumprod(
6219+
self,
6220+
axis: Axis | None = None,
6221+
numeric_only: bool = False,
6222+
skipna: bool = True,
6223+
*args,
6224+
**kwargs,
6225+
):
6226+
return NDFrame.cumprod(self, axis, numeric_only, skipna, *args, **kwargs)

pandas/tests/groupby/test_api.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ 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 = {"skipna"}
187+
exclude_expected = {"args", "kwargs"}
188+
exclude_result = {"numeric_only"}
188189
elif groupby_func in ("pct_change",):
189190
exclude_expected = {"kwargs"}
190191
exclude_result = {"axis"}
@@ -242,7 +243,7 @@ def test_series_consistency(request, groupby_func):
242243
exclude_expected = {"skipna", "args"}
243244
exclude_result = {"numeric_only"}
244245
elif groupby_func in ("cumprod", "cumsum"):
245-
exclude_expected = {"skipna"}
246+
exclude_expected = {"args", "kwargs"}
246247
elif groupby_func in ("pct_change",):
247248
exclude_expected = {"kwargs"}
248249
exclude_result = {"axis"}

pandas/tests/groupby/test_function.py

+9-12
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ def test_axis1_numeric_only(request, groupby_func, numeric_only):
547547
kwargs["numeric_only"] = numeric_only
548548

549549
# Functions without numeric_only and axis args
550-
no_args = ("cumprod", "cumsum", "diff", "fillna", "pct_change", "rank", "shift")
550+
no_args = ("diff", "fillna", "pct_change", "rank", "shift")
551551
# Functions with axis args
552552
has_axis = (
553553
"cumprod",
@@ -565,13 +565,8 @@ 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-
if groupby_func in ["cumprod", "cumsum"]:
569-
with pytest.raises(TypeError, match=msg):
570-
with tm.assert_produces_warning(FutureWarning, match=warn_msg):
571-
method(*args, **kwargs)
572-
else:
573-
with pytest.raises(TypeError, match=msg):
574-
method(*args, **kwargs)
568+
with pytest.raises(TypeError, match=msg):
569+
method(*args, **kwargs)
575570
elif groupby_func not in has_axis:
576571
msg = "got an unexpected keyword argument 'axis'"
577572
with pytest.raises(TypeError, match=msg):
@@ -814,11 +809,13 @@ def test_numpy_compat(func):
814809
g = df.groupby("A")
815810

816811
msg = "numpy operations are not valid with groupby"
812+
warn_msg = f"DataFrameGroupBy.{func} with axis=1 is deprecated"
817813

818-
with pytest.raises(UnsupportedFunctionCall, match=msg):
819-
getattr(g, func)(1, 2, 3)
820-
with pytest.raises(UnsupportedFunctionCall, match=msg):
821-
getattr(g, func)(foo=1)
814+
with pytest.raises(FutureWarning, match=warn_msg):
815+
with pytest.raises(UnsupportedFunctionCall, match=msg):
816+
getattr(g, func)(1, 2, 3)
817+
with pytest.raises(UnsupportedFunctionCall, match=msg):
818+
getattr(g, func)(foo=1)
822819

823820

824821
def test_cummin(dtypes_for_minmax):

0 commit comments

Comments
 (0)