@@ -93,7 +93,6 @@ def get_window_bounds(
93
93
94
94
end = np .clip (end , 0 , num_values )
95
95
start = np .clip (start , 0 , num_values )
96
-
97
96
return start , end
98
97
99
98
@@ -266,9 +265,8 @@ def get_window_bounds(
266
265
)
267
266
268
267
start = np .arange (num_values , dtype = "int64" )
269
- end_s = start [: - self .window_size ] + self .window_size
270
- end_e = np .full (self .window_size , num_values , dtype = "int64" )
271
- end = np .concatenate ([end_s , end_e ])
268
+ end = start + self .window_size
269
+ end [end > num_values ] = num_values
272
270
273
271
return start , end
274
272
@@ -280,7 +278,7 @@ def __init__(
280
278
self ,
281
279
index_array : np .ndarray | None = None ,
282
280
window_size : int = 0 ,
283
- groupby_indicies : dict | None = None ,
281
+ groupby_indices : dict | None = None ,
284
282
window_indexer : type [BaseIndexer ] = BaseIndexer ,
285
283
indexer_kwargs : dict | None = None ,
286
284
** kwargs ,
@@ -294,7 +292,7 @@ def __init__(
294
292
the groups
295
293
window_size : int
296
294
window size during the windowing operation
297
- groupby_indicies : dict or None
295
+ groupby_indices : dict or None
298
296
dict of {group label: [positional index of rows belonging to the group]}
299
297
window_indexer : BaseIndexer
300
298
BaseIndexer class determining the start and end bounds of each group
@@ -303,11 +301,13 @@ def __init__(
303
301
**kwargs :
304
302
keyword arguments that will be available when get_window_bounds is called
305
303
"""
306
- self .groupby_indicies = groupby_indicies or {}
304
+ self .groupby_indices = groupby_indices or {}
307
305
self .window_indexer = window_indexer
308
- self .indexer_kwargs = indexer_kwargs or {}
306
+ self .indexer_kwargs = indexer_kwargs . copy () if indexer_kwargs else {}
309
307
super ().__init__ (
310
- index_array , self .indexer_kwargs .pop ("window_size" , window_size ), ** kwargs
308
+ index_array = index_array ,
309
+ window_size = self .indexer_kwargs .pop ("window_size" , window_size ),
310
+ ** kwargs ,
311
311
)
312
312
313
313
@Appender (get_window_bounds_doc )
@@ -323,8 +323,8 @@ def get_window_bounds(
323
323
# 3) Append the window bounds in group order
324
324
start_arrays = []
325
325
end_arrays = []
326
- window_indicies_start = 0
327
- for key , indices in self .groupby_indicies .items ():
326
+ window_indices_start = 0
327
+ for key , indices in self .groupby_indices .items ():
328
328
index_array : np .ndarray | None
329
329
330
330
if self .index_array is not None :
@@ -341,18 +341,18 @@ def get_window_bounds(
341
341
)
342
342
start = start .astype (np .int64 )
343
343
end = end .astype (np .int64 )
344
- # Cannot use groupby_indicies as they might not be monotonic with the object
344
+ # Cannot use groupby_indices as they might not be monotonic with the object
345
345
# we're rolling over
346
- window_indicies = np .arange (
347
- window_indicies_start , window_indicies_start + len (indices )
346
+ window_indices = np .arange (
347
+ window_indices_start , window_indices_start + len (indices )
348
348
)
349
- window_indicies_start += len (indices )
349
+ window_indices_start += len (indices )
350
350
# Extend as we'll be slicing window like [start, end)
351
- window_indicies = np .append (
352
- window_indicies , [ window_indicies [ - 1 ] + 1 ]
353
- ). astype ( np . int64 )
354
- start_arrays .append (window_indicies .take (ensure_platform_int (start )))
355
- end_arrays .append (window_indicies .take (ensure_platform_int (end )))
351
+ window_indices = np .append ( window_indices , [ window_indices [ - 1 ] + 1 ]). astype (
352
+ np . int64
353
+ )
354
+ start_arrays .append (window_indices .take (ensure_platform_int (start )))
355
+ end_arrays .append (window_indices .take (ensure_platform_int (end )))
356
356
start = np .concatenate (start_arrays )
357
357
end = np .concatenate (end_arrays )
358
358
return start , end
0 commit comments