BUG: Add ``numeric_only`` to function signature of ``DataFrameGroupBy.cumprod`` and ``DataFrameGroupBy.cumsum`
Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Both methods support numeric only but it goes through args or kwargs, which is annoying signature wise.
Issue Description
Add the keyword with the appropriate default
Expected Behavior
See above
Installed Versions
Replace this line with the output of pd.show_versions()
take
@phofl something like?
@final
@Substitution(name="groupby")
@Appender(_common_see_also)
def cumprod(
self, axis: Axis | lib.NoDefault = lib.no_default, numeric_only: bool = False, *args, **kwargs
) -> NDFrameT:
"""
Cumulative product for each group.
Returns
-------
Series or DataFrame
"""
nv.validate_groupby_func("cumprod", args, kwargs, ["skipna"])
if axis is not lib.no_default:
axis = self.obj._get_axis_number(axis)
self._deprecate_axis(axis, "cumprod")
else:
axis = 0
if axis != 0:
f = lambda x: x.cumprod(axis=axis, **kwargs)
return self._python_apply_general(f, self._selected_obj, is_transform=True)
return self._cython_transform("cumprod", numeric_only=numeric_only, **kwargs)
@final
@Substitution(name="groupby")
@Appender(_common_see_also)
def cumsum(
self, axis: Axis | lib.NoDefault = lib.no_default, numeric_only: bool = False, *args, **kwargs
) -> NDFrameT:
"""
Cumulative sum for each group.
Returns
-------
Series or DataFrame
"""
nv.validate_groupby_func("cumsum", args, kwargs, ["skipna"])
if axis is not lib.no_default:
axis = self.obj._get_axis_number(axis)
self._deprecate_axis(axis, "cumsum")
else:
axis = 0
if axis != 0:
f = lambda x: x.cumsum(axis=axis, **kwargs)
return self._python_apply_general(f, self._selected_obj, is_transform=True)
return self._cython_transform("cumsum", numeric_only=numeric_only, **kwargs)
Yeah, we should probably add skipna as well
Sure
I can look into this if it's still open @phofl @mroeschke ?
@ShashwatAgrawal20 are you working on this or can I take it up?
@ShashwatAgrawal20 are you working on this or can I take it up?
Go ahead
take
take
@phofl I think the only way we can avoid making this a potentially breaking change is to use the following signature
def cumprod(
self,
axis: Axis | lib.NoDefault = lib.no_default,
*args,
numeric_only: bool = False,
skipna: bool = True,
**kwargs
) -> NDFrameT:
This accounts for anyone passing in redundant positional/keyword arguments. The alternative would be to remove args and kwargs altogether. Is that something we'd be happy doing?
If this issue is still open, I'd like to take it
Hi @willhsp! Are you still working on this? Would love to contribute to this issue if you are not continuing. Thanks!
take