Skip to content

Commit 2658259

Browse files
jordan-d-murphypmhatre1
authored andcommitted
DOC: fix PR02 errors in docstring for pandas.core.groupby.DataFrameGroupBy.rolling and pandas.core.groupby.SeriesGroupBy.rolling (pandas-dev#57334)
* DOC: fix PR02 errors in docstring for pandas.core.groupby.DataFrameGroupBy.rolling and pandas.core.groupby.SeriesGroupBy.rolling * added default values to rolling() parameters * Update test case test_rolling_wrong_param_min_period * Updated test case wording * add escape sequence to regex * Updating regex to accept multiple origin functions
1 parent f509642 commit 2658259

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

ci/code_checks.sh

-2
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
137137
pandas.Interval\
138138
pandas.Grouper\
139139
pandas.core.groupby.DataFrameGroupBy.nth\
140-
pandas.core.groupby.DataFrameGroupBy.rolling\
141140
pandas.core.groupby.SeriesGroupBy.nth\
142-
pandas.core.groupby.SeriesGroupBy.rolling\
143141
pandas.core.groupby.DataFrameGroupBy.plot\
144142
pandas.core.groupby.SeriesGroupBy.plot # There should be no backslash in the final line, please keep this comment in the last ignored function
145143
RET=$(($RET + $?)) ; echo $MSG "DONE"

pandas/core/groupby/groupby.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class providing the base-class of operations.
4747
DtypeObj,
4848
FillnaOptions,
4949
IndexLabel,
50+
IntervalClosedType,
5051
NDFrameT,
5152
PositionalIndexer,
5253
RandomState,
@@ -139,6 +140,7 @@ class providing the base-class of operations.
139140
)
140141

141142
if TYPE_CHECKING:
143+
from pandas._libs.tslibs import BaseOffset
142144
from pandas._typing import (
143145
Any,
144146
Concatenate,
@@ -147,6 +149,7 @@ class providing the base-class of operations.
147149
T,
148150
)
149151

152+
from pandas.core.indexers.objects import BaseIndexer
150153
from pandas.core.resample import Resampler
151154
from pandas.core.window import (
152155
ExpandingGroupby,
@@ -3616,7 +3619,16 @@ def resample(self, rule, *args, include_groups: bool = True, **kwargs) -> Resamp
36163619
)
36173620

36183621
@final
3619-
def rolling(self, *args, **kwargs) -> RollingGroupby:
3622+
def rolling(
3623+
self,
3624+
window: int | datetime.timedelta | str | BaseOffset | BaseIndexer,
3625+
min_periods: int | None = None,
3626+
center: bool = False,
3627+
win_type: str | None = None,
3628+
on: str | None = None,
3629+
closed: IntervalClosedType | None = None,
3630+
method: str = "single",
3631+
) -> RollingGroupby:
36203632
"""
36213633
Return a rolling grouper, providing rolling functionality per group.
36223634
@@ -3746,10 +3758,15 @@ def rolling(self, *args, **kwargs) -> RollingGroupby:
37463758

37473759
return RollingGroupby(
37483760
self._selected_obj,
3749-
*args,
3761+
window=window,
3762+
min_periods=min_periods,
3763+
center=center,
3764+
win_type=win_type,
3765+
on=on,
3766+
closed=closed,
3767+
method=method,
37503768
_grouper=self._grouper,
37513769
_as_index=self.as_index,
3752-
**kwargs,
37533770
)
37543771

37553772
@final

pandas/tests/groupby/test_groupby.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2423,7 +2423,9 @@ def test_rolling_wrong_param_min_period():
24232423
test_df = DataFrame([name_l, val_l]).T
24242424
test_df.columns = ["name", "val"]
24252425

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

0 commit comments

Comments
 (0)