8
8
9
9
from pandas ._libs .tslibs import BaseOffset
10
10
from pandas ._libs .window .indexers import calculate_variable_window_bounds
11
- from pandas .util ._decorators import Appender
12
11
13
12
from pandas .core .dtypes .common import ensure_platform_int
14
13
15
14
from pandas .core .indexes .datetimes import DatetimeIndex
16
15
17
16
from pandas .tseries .offsets import Nano
18
17
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
-
46
18
47
19
class BaseIndexer :
48
20
"""
@@ -95,7 +67,6 @@ def __init__(
95
67
for key , value in kwargs .items ():
96
68
setattr (self , key , value )
97
69
98
- @Appender (get_window_bounds_doc )
99
70
def get_window_bounds (
100
71
self ,
101
72
num_values : int = 0 ,
@@ -104,13 +75,38 @@ def get_window_bounds(
104
75
closed : str | None = None ,
105
76
step : int | None = None ,
106
77
) -> 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
+ """
107
104
raise NotImplementedError
108
105
109
106
110
107
class FixedWindowIndexer (BaseIndexer ):
111
108
"""Creates window boundaries that are of fixed length."""
112
109
113
- @Appender (get_window_bounds_doc )
114
110
def get_window_bounds (
115
111
self ,
116
112
num_values : int = 0 ,
@@ -119,6 +115,32 @@ def get_window_bounds(
119
115
closed : str | None = None ,
120
116
step : int | None = None ,
121
117
) -> 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
+ """
122
144
if center or self .window_size == 0 :
123
145
offset = (self .window_size - 1 ) // 2
124
146
else :
@@ -140,7 +162,6 @@ def get_window_bounds(
140
162
class VariableWindowIndexer (BaseIndexer ):
141
163
"""Creates window boundaries that are of variable length, namely for time series."""
142
164
143
- @Appender (get_window_bounds_doc )
144
165
def get_window_bounds (
145
166
self ,
146
167
num_values : int = 0 ,
@@ -149,6 +170,32 @@ def get_window_bounds(
149
170
closed : str | None = None ,
150
171
step : int | None = None ,
151
172
) -> 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
+ """
152
199
# error: Argument 4 to "calculate_variable_window_bounds" has incompatible
153
200
# type "Optional[bool]"; expected "bool"
154
201
# error: Argument 6 to "calculate_variable_window_bounds" has incompatible
@@ -240,7 +287,6 @@ def __init__(
240
287
raise ValueError ("offset must be a DateOffset-like object." )
241
288
self .offset = offset
242
289
243
- @Appender (get_window_bounds_doc )
244
290
def get_window_bounds (
245
291
self ,
246
292
num_values : int = 0 ,
@@ -249,6 +295,32 @@ def get_window_bounds(
249
295
closed : str | None = None ,
250
296
step : int | None = None ,
251
297
) -> 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
+ """
252
324
if step is not None :
253
325
raise NotImplementedError ("step not implemented for variable offset window" )
254
326
if num_values <= 0 :
@@ -321,7 +393,6 @@ def get_window_bounds(
321
393
class ExpandingIndexer (BaseIndexer ):
322
394
"""Calculate expanding window bounds, mimicking df.expanding()"""
323
395
324
- @Appender (get_window_bounds_doc )
325
396
def get_window_bounds (
326
397
self ,
327
398
num_values : int = 0 ,
@@ -330,6 +401,32 @@ def get_window_bounds(
330
401
closed : str | None = None ,
331
402
step : int | None = None ,
332
403
) -> 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
+ """
333
430
return (
334
431
np .zeros (num_values , dtype = np .int64 ),
335
432
np .arange (1 , num_values + 1 , dtype = np .int64 ),
@@ -381,7 +478,6 @@ class FixedForwardWindowIndexer(BaseIndexer):
381
478
4 4.0
382
479
"""
383
480
384
- @Appender (get_window_bounds_doc )
385
481
def get_window_bounds (
386
482
self ,
387
483
num_values : int = 0 ,
@@ -390,6 +486,32 @@ def get_window_bounds(
390
486
closed : str | None = None ,
391
487
step : int | None = None ,
392
488
) -> 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
+ """
393
515
if center :
394
516
raise ValueError ("Forward-looking windows can't have center=True" )
395
517
if closed is not None :
@@ -446,7 +568,6 @@ def __init__(
446
568
** kwargs ,
447
569
)
448
570
449
- @Appender (get_window_bounds_doc )
450
571
def get_window_bounds (
451
572
self ,
452
573
num_values : int = 0 ,
@@ -455,6 +576,32 @@ def get_window_bounds(
455
576
closed : str | None = None ,
456
577
step : int | None = None ,
457
578
) -> 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
+ """
458
605
# 1) For each group, get the indices that belong to the group
459
606
# 2) Use the indices to calculate the start & end bounds of the window
460
607
# 3) Append the window bounds in group order
@@ -503,7 +650,6 @@ def get_window_bounds(
503
650
class ExponentialMovingWindowIndexer (BaseIndexer ):
504
651
"""Calculate ewm window bounds (the entire window)"""
505
652
506
- @Appender (get_window_bounds_doc )
507
653
def get_window_bounds (
508
654
self ,
509
655
num_values : int = 0 ,
@@ -512,4 +658,30 @@ def get_window_bounds(
512
658
closed : str | None = None ,
513
659
step : int | None = None ,
514
660
) -> 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
+ """
515
687
return np .array ([0 ], dtype = np .int64 ), np .array ([num_values ], dtype = np .int64 )
0 commit comments