Skip to content

DOC: Updated groupby.expanding arguments #61352

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

Merged
merged 2 commits into from
Apr 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3809,19 +3809,26 @@ def rolling(
)

@final
def expanding(self, *args, **kwargs) -> ExpandingGroupby:
def expanding(
self,
min_periods: int = 1,
method: str = "single",
) -> ExpandingGroupby:
"""
Return an expanding grouper, providing expanding functionality per group.

Arguments are the same as `:meth:DataFrame.rolling` except that ``step`` cannot
be specified.
Comment on lines -3816 to -3817
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't rolling accept many more arguments, e.g. window?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #61361 just to be sure this doesn't get forgotten.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was incorrect, the signature is fine here.


Parameters
----------
*args : tuple
Positional arguments passed to the expanding window constructor.
**kwargs : dict
Keyword arguments passed to the expanding window constructor.
min_periods : int, default 1
Minimum number of observations in window required to have a value;
otherwise, result is ``np.nan``.

method : str {'single', 'table'}, default 'single'
Execute the expanding operation per single column or row (``'single'``)
or over the entire object (``'table'``).

This argument is only implemented when specifying ``engine='numba'``
in the method call.

Returns
-------
Expand All @@ -3844,7 +3851,7 @@ def expanding(self, *args, **kwargs) -> ExpandingGroupby:
... }
... )
>>> df
Class Value
Class Value
0 A 10
1 A 20
2 A 30
Expand All @@ -3853,7 +3860,7 @@ def expanding(self, *args, **kwargs) -> ExpandingGroupby:
5 B 60

>>> df.groupby("Class").expanding().mean()
Value
Value
Class
A 0 10.0
1 15.0
Expand All @@ -3866,9 +3873,9 @@ def expanding(self, *args, **kwargs) -> ExpandingGroupby:

return ExpandingGroupby(
self._selected_obj,
*args,
min_periods=min_periods,
method=method,
_grouper=self._grouper,
**kwargs,
)

@final
Expand Down
Loading