Skip to content

Commit 1b574c1

Browse files
author
Kevin Sheppard
committed
ENH: Add step to rolling
1 parent 7b84785 commit 1b574c1

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

pandas-stubs/_typing.pyi

+2
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,6 @@ class StyleExportDict(TypedDict, total=False):
302302
hide_column_names: bool
303303
css: dict[str, str | int]
304304

305+
RollingMethod = Literal["single", "table"]
306+
305307
__all__ = ["npt", "type_t"]

pandas-stubs/core/frame.pyi

+8-3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ from pandas._typing import (
8484
ReadBuffer,
8585
Renamer,
8686
ReplaceMethod,
87+
RollingMethod,
8788
Scalar,
8889
ScalarT,
8990
SeriesAxisType,
@@ -1429,7 +1430,7 @@ class DataFrame(NDFrame, OpsMixin):
14291430
self,
14301431
min_periods: int = ...,
14311432
axis: AxisType = ...,
1432-
method: Literal["single", "table"] = ...,
1433+
method: RollingMethod = ...,
14331434
) -> Expanding[DataFrame]: ...
14341435
@overload
14351436
def ffill(
@@ -1763,26 +1764,30 @@ class DataFrame(NDFrame, OpsMixin):
17631764
@overload
17641765
def rolling(
17651766
self,
1766-
window,
1767+
window: int,
17671768
min_periods: int | None = ...,
17681769
center: _bool = ...,
17691770
*,
17701771
win_type: _str,
17711772
on: Hashable | None = ...,
17721773
axis: AxisType = ...,
17731774
closed: IntervalClosedType | None = ...,
1775+
step: int | None = ...,
1776+
method: RollingMethod = ...,
17741777
) -> Window[DataFrame]: ...
17751778
@overload
17761779
def rolling(
17771780
self,
1778-
window,
1781+
window: int,
17791782
min_periods: int | None = ...,
17801783
center: _bool = ...,
17811784
*,
17821785
win_type: None = ...,
17831786
on: Hashable | None = ...,
17841787
axis: AxisType = ...,
17851788
closed: IntervalClosedType | None = ...,
1789+
step: int | None = ...,
1790+
method: RollingMethod = ...,
17861791
) -> Rolling[DataFrame]: ...
17871792
def rpow(
17881793
self,

pandas-stubs/core/series.pyi

+8-3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ from pandas._typing import (
8888
QuantileInterpolation,
8989
Renamer,
9090
ReplaceMethod,
91+
RollingMethod,
9192
Scalar,
9293
SeriesAxisType,
9394
SortKind,
@@ -1318,7 +1319,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
13181319
self,
13191320
min_periods: int = ...,
13201321
axis: SeriesAxisType = ...,
1321-
method: Literal["single", "table"] = ...,
1322+
method: RollingMethod = ...,
13221323
) -> Expanding[Series]: ...
13231324
def floordiv(
13241325
self,
@@ -1496,26 +1497,30 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
14961497
@overload
14971498
def rolling(
14981499
self,
1499-
window,
1500+
window: int,
15001501
min_periods: int | None = ...,
15011502
center: _bool = ...,
15021503
*,
15031504
win_type: _str,
15041505
on: _str | None = ...,
15051506
axis: SeriesAxisType = ...,
15061507
closed: _str | None = ...,
1508+
step: int | None = ...,
1509+
method: RollingMethod = ...,
15071510
) -> Window[Series]: ...
15081511
@overload
15091512
def rolling(
15101513
self,
1511-
window,
1514+
window: int,
15121515
min_periods: int | None = ...,
15131516
center: _bool = ...,
15141517
*,
15151518
win_type: None = ...,
15161519
on: _str | None = ...,
15171520
axis: SeriesAxisType = ...,
15181521
closed: _str | None = ...,
1522+
step: int | None = ...,
1523+
method: RollingMethod = ...,
15191524
) -> Rolling[Series]: ...
15201525
def rpow(
15211526
self,

pandas-stubs/core/window/ewm.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from typing import (
22
Any,
33
Generic,
4-
Literal,
54
overload,
65
)
76

@@ -18,6 +17,7 @@ from pandas._typing import (
1817
AggFuncTypeSeriesToFrame,
1918
Axis,
2019
NDFrameT,
20+
RollingMethod,
2121
TimedeltaConvertibleTypes,
2222
WindowingEngine,
2323
WindowingEngineKwargs,
@@ -36,7 +36,7 @@ class ExponentialMovingWindow(BaseWindow[NDFrameT], Generic[NDFrameT]):
3636
ignore_na: bool = ...,
3737
axis: Axis = ...,
3838
times: str | np.ndarray | Series | None = ...,
39-
method: Literal["single", "table"] = ...,
39+
method: RollingMethod = ...,
4040
) -> None: ...
4141
@overload
4242
def aggregate(

tests/test_windowing.py

+8
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,11 @@ def test_ewm_aggregate_series() -> None:
304304
DataFrame,
305305
)
306306
check(assert_type(S.ewm(span=10).agg("sum"), Series), Series)
307+
308+
309+
def test_rolling_step_method():
310+
check(
311+
assert_type(DF.rolling(10, step=5, method="single"), "Rolling[DataFrame]"),
312+
Rolling,
313+
)
314+
check(assert_type(DF.rolling(10, method="table"), "Rolling[DataFrame]"), Rolling)

0 commit comments

Comments
 (0)