diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 9c9cd2cc6650e..f48a9e11dc9e1 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -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" diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 2ac069deaad36..1ec525a0f22b8 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -47,6 +47,7 @@ class providing the base-class of operations. DtypeObj, FillnaOptions, IndexLabel, + IntervalClosedType, NDFrameT, PositionalIndexer, RandomState, @@ -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, @@ -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, @@ -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. @@ -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 diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index db45067162bc3..2d06c2f258539 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -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()