@@ -232,7 +232,7 @@ cdef class VariableWindowIndexer(WindowIndexer):
232
232
233
233
"""
234
234
def __init__ (self , ndarray input , int64_t win , int64_t minp ,
235
- ndarray index ):
235
+ ndarray index , closed = ' right ' ):
236
236
237
237
self .is_variable = 1
238
238
self .N = len (index)
@@ -249,6 +249,9 @@ cdef class VariableWindowIndexer(WindowIndexer):
249
249
# max window size
250
250
self .win = (self .end - self .start).max()
251
251
252
+ if closed not in [' right' , ' left' , ' both' , ' neither' ]:
253
+ closed = ' right'
254
+
252
255
def build (self , ndarray[int64_t] index , int64_t win ):
253
256
254
257
cdef:
@@ -261,7 +264,10 @@ cdef class VariableWindowIndexer(WindowIndexer):
261
264
N = self .N
262
265
263
266
start[0 ] = 0
264
- end[0 ] = 1
267
+ if closed in [' right' , ' both' ]:
268
+ end[0 ] = 1
269
+ else :
270
+ end[0 ] = 0
265
271
266
272
with nogil:
267
273
@@ -271,6 +277,9 @@ cdef class VariableWindowIndexer(WindowIndexer):
271
277
end_bound = index[i]
272
278
start_bound = index[i] - win
273
279
280
+ if closed in [' left' , ' both' ]:
281
+ start_bound -= 1
282
+
274
283
# advance the start bound until we are
275
284
# within the constraint
276
285
start[i] = i
@@ -286,6 +295,9 @@ cdef class VariableWindowIndexer(WindowIndexer):
286
295
else :
287
296
end[i] = end[i - 1 ]
288
297
298
+ if closed in [' left' , ' neither' ]:
299
+ end[i] -= 1
300
+
289
301
290
302
def get_window_indexer (input , win , minp , index , floor = None ,
291
303
use_mock = True ):
0 commit comments