Skip to content

BUG: Add numeric_only to function signature of DataFrameGroupBy.cumprod and `DataFrameGroupBy.cumsum #53071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
phofl opened this issue May 4, 2023 · 13 comments · Fixed by #59427
Closed
3 tasks done

Comments

@phofl
Copy link
Member

phofl commented May 4, 2023

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • 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()

@ShashwatAgrawal20
Copy link
Contributor

take

@ShashwatAgrawal20
Copy link
Contributor

ShashwatAgrawal20 commented May 4, 2023

@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)

@phofl
Copy link
Member Author

phofl commented May 4, 2023

Yeah, we should probably add skipna as well

@ShashwatAgrawal20
Copy link
Contributor

Sure

@rsm-23
Copy link
Contributor

rsm-23 commented Jun 27, 2023

I can look into this if it's still open @phofl @mroeschke ?

@rsm-23
Copy link
Contributor

rsm-23 commented Jul 1, 2023

@ShashwatAgrawal20 are you working on this or can I take it up?

@ShashwatAgrawal20
Copy link
Contributor

@ShashwatAgrawal20 are you working on this or can I take it up?

Go ahead

@ShashwatAgrawal20 ShashwatAgrawal20 removed their assignment Jul 1, 2023
@rsm-23
Copy link
Contributor

rsm-23 commented Jul 1, 2023

take

@willhsp
Copy link

willhsp commented Sep 11, 2023

take

@willhsp
Copy link

willhsp commented Sep 14, 2023

@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?

@shriyase
Copy link

If this issue is still open, I'd like to take it

@maushumee
Copy link
Contributor

Hi @willhsp! Are you still working on this? Would love to contribute to this issue if you are not continuing. Thanks!

@maushumee
Copy link
Contributor

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment