Skip to content

DOC: fix PR02 errors in docstring for pandas.core.groupby.DataFrameGroupBy.rolling and pandas.core.groupby.SeriesGroupBy.rolling #57334

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 8 commits into from
Feb 12, 2024
2 changes: 0 additions & 2 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.Interval\
pandas.Grouper\
pandas.core.groupby.DataFrameGroupBy.nth\
pandas.core.groupby.DataFrameGroupBy.rolling\
pandas.core.groupby.SeriesGroupBy.nth\
pandas.core.groupby.SeriesGroupBy.rolling\
pandas.core.groupby.DataFrameGroupBy.plot\
pandas.core.groupby.SeriesGroupBy.plot # There should be no backslash in the final line, please keep this comment in the last ignored function
RET=$(($RET + $?)) ; echo $MSG "DONE"
Expand Down
23 changes: 20 additions & 3 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class providing the base-class of operations.
DtypeObj,
FillnaOptions,
IndexLabel,
IntervalClosedType,
NDFrameT,
PositionalIndexer,
RandomState,
Expand Down Expand Up @@ -139,6 +140,7 @@ class providing the base-class of operations.
)

if TYPE_CHECKING:
from pandas._libs.tslibs import BaseOffset
from pandas._typing import (
Any,
Concatenate,
Expand All @@ -147,6 +149,7 @@ class providing the base-class of operations.
T,
)

from pandas.core.indexers.objects import BaseIndexer
from pandas.core.resample import Resampler
from pandas.core.window import (
ExpandingGroupby,
Expand Down Expand Up @@ -3616,7 +3619,16 @@ def resample(self, rule, *args, include_groups: bool = True, **kwargs) -> Resamp
)

@final
def rolling(self, *args, **kwargs) -> RollingGroupby:
def rolling(
self,
window: int | datetime.timedelta | str | BaseOffset | BaseIndexer,
min_periods: int | None = None,
center: bool = False,
win_type: str | None = None,
on: str | None = None,
closed: IntervalClosedType | None = None,
method: str = "single",
) -> RollingGroupby:
"""
Return a rolling grouper, providing rolling functionality per group.

Expand Down Expand Up @@ -3746,10 +3758,15 @@ def rolling(self, *args, **kwargs) -> RollingGroupby:

return RollingGroupby(
self._selected_obj,
*args,
window=window,
min_periods=min_periods,
center=center,
win_type=win_type,
on=on,
closed=closed,
method=method,
_grouper=self._grouper,
_as_index=self.as_index,
**kwargs,
)

@final
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2423,7 +2423,9 @@ def test_rolling_wrong_param_min_period():
test_df = DataFrame([name_l, val_l]).T
test_df.columns = ["name", "val"]

result_error_msg = r"__init__\(\) got an unexpected keyword argument 'min_period'"
result_error_msg = (
r"^[a-zA-Z._]*\(\) got an unexpected keyword argument 'min_period'$"
)
with pytest.raises(TypeError, match=result_error_msg):
test_df.groupby("name")["val"].rolling(window=2, min_period=1).sum()

Expand Down