@@ -213,9 +213,9 @@ def __getattr__(self, attr: str):
213
213
def _dir_additions (self ):
214
214
return self .obj ._dir_additions ()
215
215
216
- def _get_window (
216
+ def _get_cov_corr_window (
217
217
self , other : Optional [Union [np .ndarray , FrameOrSeries ]] = None
218
- ) -> int :
218
+ ) -> Optional [ Union [ int , timedelta , BaseOffset , BaseIndexer ]] :
219
219
"""
220
220
Return window length.
221
221
@@ -228,8 +228,6 @@ def _get_window(
228
228
-------
229
229
window : int
230
230
"""
231
- if isinstance (self .window , BaseIndexer ):
232
- return self .min_periods or 0
233
231
return self .window
234
232
235
233
@property
@@ -249,11 +247,10 @@ def __repr__(self) -> str:
249
247
return f"{ self ._window_type } [{ attrs } ]"
250
248
251
249
def __iter__ (self ):
252
- window = self ._get_window ()
253
250
obj = self ._create_data (self ._selected_obj )
254
- index = self ._get_window_indexer (window = window )
251
+ indexer = self ._get_window_indexer ()
255
252
256
- start , end = index .get_window_bounds (
253
+ start , end = indexer .get_window_bounds (
257
254
num_values = len (obj ),
258
255
min_periods = self .min_periods ,
259
256
center = self .center ,
@@ -340,15 +337,17 @@ def _get_roll_func(self, func_name: str) -> Callable[..., Any]:
340
337
)
341
338
return window_func
342
339
343
- def _get_window_indexer (self , window : int ) -> BaseIndexer :
340
+ def _get_window_indexer (self ) -> BaseIndexer :
344
341
"""
345
342
Return an indexer class that will compute the window start and end bounds
346
343
"""
347
344
if isinstance (self .window , BaseIndexer ):
348
345
return self .window
349
346
if self .is_freq_type :
350
- return VariableWindowIndexer (index_array = self ._on .asi8 , window_size = window )
351
- return FixedWindowIndexer (window_size = window )
347
+ return VariableWindowIndexer (
348
+ index_array = self ._on .asi8 , window_size = self .window
349
+ )
350
+ return FixedWindowIndexer (window_size = self .window )
352
351
353
352
def _apply_series (
354
353
self , homogeneous_func : Callable [..., ArrayLike ], name : Optional [str ] = None
@@ -428,8 +427,7 @@ def _apply(
428
427
-------
429
428
y : type of input
430
429
"""
431
- window = self ._get_window ()
432
- window_indexer = self ._get_window_indexer (window )
430
+ window_indexer = self ._get_window_indexer ()
433
431
min_periods = (
434
432
self .min_periods
435
433
if self .min_periods is not None
@@ -1750,14 +1748,10 @@ def cov(self, other=None, pairwise=None, ddof=1, **kwargs):
1750
1748
# GH 32865. We leverage rolling.mean, so we pass
1751
1749
# to the rolling constructors the data used when constructing self:
1752
1750
# window width, frequency data, or a BaseIndexer subclass
1753
- if isinstance (self .window , BaseIndexer ):
1754
- window = self .window
1755
- else :
1756
- # GH 16058: offset window
1757
- if self .is_freq_type :
1758
- window = self .win_freq
1759
- else :
1760
- window = self ._get_window (other )
1751
+ # GH 16058: offset window
1752
+ window = (
1753
+ self ._get_cov_corr_window (other ) if not self .is_freq_type else self .win_freq
1754
+ )
1761
1755
1762
1756
def _get_cov (X , Y ):
1763
1757
# GH #12373 : rolling functions error on float32 data
@@ -1899,10 +1893,10 @@ def corr(self, other=None, pairwise=None, **kwargs):
1899
1893
# GH 32865. We leverage rolling.cov and rolling.std here, so we pass
1900
1894
# to the rolling constructors the data used when constructing self:
1901
1895
# window width, frequency data, or a BaseIndexer subclass
1902
- if isinstance ( self . window , BaseIndexer ):
1903
- window = self . window
1904
- else :
1905
- window = self . _get_window ( other ) if not self . is_freq_type else self . win_freq
1896
+ # GH 16058: offset window
1897
+ window = (
1898
+ self . _get_cov_corr_window ( other ) if not self . is_freq_type else self . win_freq
1899
+ )
1906
1900
1907
1901
def _get_corr (a , b ):
1908
1902
a = a .rolling (
@@ -2208,28 +2202,25 @@ class RollingGroupby(BaseWindowGroupby, Rolling):
2208
2202
Provide a rolling groupby implementation.
2209
2203
"""
2210
2204
2211
- def _get_window_indexer (self , window : int ) -> GroupbyIndexer :
2205
+ def _get_window_indexer (self ) -> GroupbyIndexer :
2212
2206
"""
2213
2207
Return an indexer class that will compute the window start and end bounds
2214
2208
2215
- Parameters
2216
- ----------
2217
- window : int
2218
- window size for FixedWindowIndexer
2219
-
2220
2209
Returns
2221
2210
-------
2222
2211
GroupbyIndexer
2223
2212
"""
2224
2213
rolling_indexer : Type [BaseIndexer ]
2225
2214
indexer_kwargs : Optional [Dict [str , Any ]] = None
2226
2215
index_array = self ._on .asi8
2216
+ window = self .window
2227
2217
if isinstance (self .window , BaseIndexer ):
2228
2218
rolling_indexer = type (self .window )
2229
2219
indexer_kwargs = self .window .__dict__
2230
2220
assert isinstance (indexer_kwargs , dict ) # for mypy
2231
2221
# We'll be using the index of each group later
2232
2222
indexer_kwargs .pop ("index_array" , None )
2223
+ window = 0
2233
2224
elif self .is_freq_type :
2234
2225
rolling_indexer = VariableWindowIndexer
2235
2226
else :
0 commit comments