88
99from pandas ._libs .tslibs import BaseOffset
1010from pandas ._libs .window .indexers import calculate_variable_window_bounds
11- from pandas .util ._decorators import Appender
1211
1312from pandas .core .dtypes .common import ensure_platform_int
1413
1514from pandas .core .indexes .datetimes import DatetimeIndex
1615
1716from pandas .tseries .offsets import Nano
1817
19- get_window_bounds_doc = """
20- Computes the bounds of a window.
21-
22- Parameters
23- ----------
24- num_values : int, default 0
25- number of values that will be aggregated over
26- window_size : int, default 0
27- the number of rows in a window
28- min_periods : int, default None
29- min_periods passed from the top level rolling API
30- center : bool, default None
31- center passed from the top level rolling API
32- closed : str, default None
33- closed passed from the top level rolling API
34- step : int, default None
35- step passed from the top level rolling API
36- .. versionadded:: 1.5
37- win_type : str, default None
38- win_type passed from the top level rolling API
39-
40- Returns
41- -------
42- A tuple of ndarray[int64]s, indicating the boundaries of each
43- window
44- """
45-
4618
4719class BaseIndexer :
4820 """
@@ -95,7 +67,6 @@ def __init__(
9567 for key , value in kwargs .items ():
9668 setattr (self , key , value )
9769
98- @Appender (get_window_bounds_doc )
9970 def get_window_bounds (
10071 self ,
10172 num_values : int = 0 ,
@@ -104,13 +75,38 @@ def get_window_bounds(
10475 closed : str | None = None ,
10576 step : int | None = None ,
10677 ) -> tuple [np .ndarray , np .ndarray ]:
78+ """
79+ Computes the bounds of a window.
80+
81+ Parameters
82+ ----------
83+ num_values : int, default 0
84+ number of values that will be aggregated over
85+ window_size : int, default 0
86+ the number of rows in a window
87+ min_periods : int, default None
88+ min_periods passed from the top level rolling API
89+ center : bool, default None
90+ center passed from the top level rolling API
91+ closed : str, default None
92+ closed passed from the top level rolling API
93+ step : int, default None
94+ step passed from the top level rolling API
95+ .. versionadded:: 1.5
96+ win_type : str, default None
97+ win_type passed from the top level rolling API
98+
99+ Returns
100+ -------
101+ A tuple of ndarray[int64]s, indicating the boundaries of each
102+ window
103+ """
107104 raise NotImplementedError
108105
109106
110107class FixedWindowIndexer (BaseIndexer ):
111108 """Creates window boundaries that are of fixed length."""
112109
113- @Appender (get_window_bounds_doc )
114110 def get_window_bounds (
115111 self ,
116112 num_values : int = 0 ,
@@ -119,6 +115,32 @@ def get_window_bounds(
119115 closed : str | None = None ,
120116 step : int | None = None ,
121117 ) -> tuple [np .ndarray , np .ndarray ]:
118+ """
119+ Computes the bounds of a window.
120+
121+ Parameters
122+ ----------
123+ num_values : int, default 0
124+ number of values that will be aggregated over
125+ window_size : int, default 0
126+ the number of rows in a window
127+ min_periods : int, default None
128+ min_periods passed from the top level rolling API
129+ center : bool, default None
130+ center passed from the top level rolling API
131+ closed : str, default None
132+ closed passed from the top level rolling API
133+ step : int, default None
134+ step passed from the top level rolling API
135+ .. versionadded:: 1.5
136+ win_type : str, default None
137+ win_type passed from the top level rolling API
138+
139+ Returns
140+ -------
141+ A tuple of ndarray[int64]s, indicating the boundaries of each
142+ window
143+ """
122144 if center or self .window_size == 0 :
123145 offset = (self .window_size - 1 ) // 2
124146 else :
@@ -140,7 +162,6 @@ def get_window_bounds(
140162class VariableWindowIndexer (BaseIndexer ):
141163 """Creates window boundaries that are of variable length, namely for time series."""
142164
143- @Appender (get_window_bounds_doc )
144165 def get_window_bounds (
145166 self ,
146167 num_values : int = 0 ,
@@ -149,6 +170,32 @@ def get_window_bounds(
149170 closed : str | None = None ,
150171 step : int | None = None ,
151172 ) -> tuple [np .ndarray , np .ndarray ]:
173+ """
174+ Computes the bounds of a window.
175+
176+ Parameters
177+ ----------
178+ num_values : int, default 0
179+ number of values that will be aggregated over
180+ window_size : int, default 0
181+ the number of rows in a window
182+ min_periods : int, default None
183+ min_periods passed from the top level rolling API
184+ center : bool, default None
185+ center passed from the top level rolling API
186+ closed : str, default None
187+ closed passed from the top level rolling API
188+ step : int, default None
189+ step passed from the top level rolling API
190+ .. versionadded:: 1.5
191+ win_type : str, default None
192+ win_type passed from the top level rolling API
193+
194+ Returns
195+ -------
196+ A tuple of ndarray[int64]s, indicating the boundaries of each
197+ window
198+ """
152199 # error: Argument 4 to "calculate_variable_window_bounds" has incompatible
153200 # type "Optional[bool]"; expected "bool"
154201 # error: Argument 6 to "calculate_variable_window_bounds" has incompatible
@@ -240,7 +287,6 @@ def __init__(
240287 raise ValueError ("offset must be a DateOffset-like object." )
241288 self .offset = offset
242289
243- @Appender (get_window_bounds_doc )
244290 def get_window_bounds (
245291 self ,
246292 num_values : int = 0 ,
@@ -249,6 +295,32 @@ def get_window_bounds(
249295 closed : str | None = None ,
250296 step : int | None = None ,
251297 ) -> tuple [np .ndarray , np .ndarray ]:
298+ """
299+ Computes the bounds of a window.
300+
301+ Parameters
302+ ----------
303+ num_values : int, default 0
304+ number of values that will be aggregated over
305+ window_size : int, default 0
306+ the number of rows in a window
307+ min_periods : int, default None
308+ min_periods passed from the top level rolling API
309+ center : bool, default None
310+ center passed from the top level rolling API
311+ closed : str, default None
312+ closed passed from the top level rolling API
313+ step : int, default None
314+ step passed from the top level rolling API
315+ .. versionadded:: 1.5
316+ win_type : str, default None
317+ win_type passed from the top level rolling API
318+
319+ Returns
320+ -------
321+ A tuple of ndarray[int64]s, indicating the boundaries of each
322+ window
323+ """
252324 if step is not None :
253325 raise NotImplementedError ("step not implemented for variable offset window" )
254326 if num_values <= 0 :
@@ -321,7 +393,6 @@ def get_window_bounds(
321393class ExpandingIndexer (BaseIndexer ):
322394 """Calculate expanding window bounds, mimicking df.expanding()"""
323395
324- @Appender (get_window_bounds_doc )
325396 def get_window_bounds (
326397 self ,
327398 num_values : int = 0 ,
@@ -330,6 +401,32 @@ def get_window_bounds(
330401 closed : str | None = None ,
331402 step : int | None = None ,
332403 ) -> tuple [np .ndarray , np .ndarray ]:
404+ """
405+ Computes the bounds of a window.
406+
407+ Parameters
408+ ----------
409+ num_values : int, default 0
410+ number of values that will be aggregated over
411+ window_size : int, default 0
412+ the number of rows in a window
413+ min_periods : int, default None
414+ min_periods passed from the top level rolling API
415+ center : bool, default None
416+ center passed from the top level rolling API
417+ closed : str, default None
418+ closed passed from the top level rolling API
419+ step : int, default None
420+ step passed from the top level rolling API
421+ .. versionadded:: 1.5
422+ win_type : str, default None
423+ win_type passed from the top level rolling API
424+
425+ Returns
426+ -------
427+ A tuple of ndarray[int64]s, indicating the boundaries of each
428+ window
429+ """
333430 return (
334431 np .zeros (num_values , dtype = np .int64 ),
335432 np .arange (1 , num_values + 1 , dtype = np .int64 ),
@@ -381,7 +478,6 @@ class FixedForwardWindowIndexer(BaseIndexer):
381478 4 4.0
382479 """
383480
384- @Appender (get_window_bounds_doc )
385481 def get_window_bounds (
386482 self ,
387483 num_values : int = 0 ,
@@ -390,6 +486,32 @@ def get_window_bounds(
390486 closed : str | None = None ,
391487 step : int | None = None ,
392488 ) -> tuple [np .ndarray , np .ndarray ]:
489+ """
490+ Computes the bounds of a window.
491+
492+ Parameters
493+ ----------
494+ num_values : int, default 0
495+ number of values that will be aggregated over
496+ window_size : int, default 0
497+ the number of rows in a window
498+ min_periods : int, default None
499+ min_periods passed from the top level rolling API
500+ center : bool, default None
501+ center passed from the top level rolling API
502+ closed : str, default None
503+ closed passed from the top level rolling API
504+ step : int, default None
505+ step passed from the top level rolling API
506+ .. versionadded:: 1.5
507+ win_type : str, default None
508+ win_type passed from the top level rolling API
509+
510+ Returns
511+ -------
512+ A tuple of ndarray[int64]s, indicating the boundaries of each
513+ window
514+ """
393515 if center :
394516 raise ValueError ("Forward-looking windows can't have center=True" )
395517 if closed is not None :
@@ -446,7 +568,6 @@ def __init__(
446568 ** kwargs ,
447569 )
448570
449- @Appender (get_window_bounds_doc )
450571 def get_window_bounds (
451572 self ,
452573 num_values : int = 0 ,
@@ -455,6 +576,32 @@ def get_window_bounds(
455576 closed : str | None = None ,
456577 step : int | None = None ,
457578 ) -> tuple [np .ndarray , np .ndarray ]:
579+ """
580+ Computes the bounds of a window.
581+
582+ Parameters
583+ ----------
584+ num_values : int, default 0
585+ number of values that will be aggregated over
586+ window_size : int, default 0
587+ the number of rows in a window
588+ min_periods : int, default None
589+ min_periods passed from the top level rolling API
590+ center : bool, default None
591+ center passed from the top level rolling API
592+ closed : str, default None
593+ closed passed from the top level rolling API
594+ step : int, default None
595+ step passed from the top level rolling API
596+ .. versionadded:: 1.5
597+ win_type : str, default None
598+ win_type passed from the top level rolling API
599+
600+ Returns
601+ -------
602+ A tuple of ndarray[int64]s, indicating the boundaries of each
603+ window
604+ """
458605 # 1) For each group, get the indices that belong to the group
459606 # 2) Use the indices to calculate the start & end bounds of the window
460607 # 3) Append the window bounds in group order
@@ -503,7 +650,6 @@ def get_window_bounds(
503650class ExponentialMovingWindowIndexer (BaseIndexer ):
504651 """Calculate ewm window bounds (the entire window)"""
505652
506- @Appender (get_window_bounds_doc )
507653 def get_window_bounds (
508654 self ,
509655 num_values : int = 0 ,
@@ -512,4 +658,30 @@ def get_window_bounds(
512658 closed : str | None = None ,
513659 step : int | None = None ,
514660 ) -> tuple [np .ndarray , np .ndarray ]:
661+ """
662+ Computes the bounds of a window.
663+
664+ Parameters
665+ ----------
666+ num_values : int, default 0
667+ number of values that will be aggregated over
668+ window_size : int, default 0
669+ the number of rows in a window
670+ min_periods : int, default None
671+ min_periods passed from the top level rolling API
672+ center : bool, default None
673+ center passed from the top level rolling API
674+ closed : str, default None
675+ closed passed from the top level rolling API
676+ step : int, default None
677+ step passed from the top level rolling API
678+ .. versionadded:: 1.5
679+ win_type : str, default None
680+ win_type passed from the top level rolling API
681+
682+ Returns
683+ -------
684+ A tuple of ndarray[int64]s, indicating the boundaries of each
685+ window
686+ """
515687 return np .array ([0 ], dtype = np .int64 ), np .array ([num_values ], dtype = np .int64 )
0 commit comments