Skip to content

Commit 34f1309

Browse files
carlosdanielcsantosjreback
authored andcommitted
Adding window slicing endpoint inclusion selection to VariableWindowIndexer
1 parent 838e09c commit 34f1309

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pandas/core/window.pyx

+14-2
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ cdef class VariableWindowIndexer(WindowIndexer):
232232
233233
"""
234234
def __init__(self, ndarray input, int64_t win, int64_t minp,
235-
ndarray index):
235+
ndarray index, closed='right'):
236236

237237
self.is_variable = 1
238238
self.N = len(index)
@@ -249,6 +249,9 @@ cdef class VariableWindowIndexer(WindowIndexer):
249249
# max window size
250250
self.win = (self.end - self.start).max()
251251

252+
if closed not in ['right', 'left', 'both', 'neither']:
253+
closed = 'right'
254+
252255
def build(self, ndarray[int64_t] index, int64_t win):
253256

254257
cdef:
@@ -261,7 +264,10 @@ cdef class VariableWindowIndexer(WindowIndexer):
261264
N = self.N
262265

263266
start[0] = 0
264-
end[0] = 1
267+
if closed in ['right', 'both']:
268+
end[0] = 1
269+
else:
270+
end[0] = 0
265271

266272
with nogil:
267273

@@ -271,6 +277,9 @@ cdef class VariableWindowIndexer(WindowIndexer):
271277
end_bound = index[i]
272278
start_bound = index[i] - win
273279

280+
if closed in ['left', 'both']:
281+
start_bound -= 1
282+
274283
# advance the start bound until we are
275284
# within the constraint
276285
start[i] = i
@@ -286,6 +295,9 @@ cdef class VariableWindowIndexer(WindowIndexer):
286295
else:
287296
end[i] = end[i - 1]
288297

298+
if closed in ['left', 'neither']:
299+
end[i] -= 1
300+
289301

290302
def get_window_indexer(input, win, minp, index, floor=None,
291303
use_mock=True):

0 commit comments

Comments
 (0)