Skip to content

Commit ec4bbc7

Browse files
carlosdanielcsantosjreback
authored andcommitted
Changing l_closed and r_closed variable names
1 parent 0e8e65c commit ec4bbc7

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed

pandas/core/window.pyx

+32-26
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ cdef class MockFixedWindowIndexer(WindowIndexer):
158158
index of the input
159159
floor: optional
160160
unit for flooring
161-
l_closed: bint
161+
left_closed: bint
162162
left endpoint closedness
163-
r_closed: bint
163+
right_closed: bint
164164
right endpoint closedness
165165
166166
"""
167167
def __init__(self, ndarray input, int64_t win, int64_t minp,
168168
object index=None, object floor=None,
169-
bint l_closed=False, bint r_closed=True):
169+
bint left_closed=False, bint right_closed=True):
170170

171171
assert index is None
172172
self.is_variable = 0
@@ -196,15 +196,15 @@ cdef class FixedWindowIndexer(WindowIndexer):
196196
index of the input
197197
floor: optional
198198
unit for flooring the unit
199-
l_closed: bint
199+
left_closed: bint
200200
left endpoint closedness
201-
r_closed: bint
201+
right_closed: bint
202202
right endpoint closedness
203203
204204
"""
205205
def __init__(self, ndarray input, int64_t win, int64_t minp,
206206
object index=None, object floor=None,
207-
bint l_closed=False, bint r_closed=True):
207+
bint left_closed=False, bint right_closed=True):
208208
cdef ndarray start_s, start_e, end_s, end_e
209209

210210
assert index is None
@@ -239,14 +239,16 @@ cdef class VariableWindowIndexer(WindowIndexer):
239239
min number of obs in a window to consider non-NaN
240240
index: ndarray
241241
index of the input
242-
l_closed: bint
242+
left_closed: bint
243243
left endpoint closedness
244-
r_closed: bint
244+
True if the left endpoint is closed, False if open
245+
right_closed: bint
245246
right endpoint closedness
247+
True if the right endpoint is closed, False if open
246248
247249
"""
248250
def __init__(self, ndarray input, int64_t win, int64_t minp,
249-
ndarray index, bint l_closed, bint r_closed):
251+
ndarray index, bint left_closed, bint right_closed):
250252

251253
self.is_variable = 1
252254
self.N = len(index)
@@ -258,13 +260,13 @@ cdef class VariableWindowIndexer(WindowIndexer):
258260
self.end = np.empty(self.N, dtype='int64')
259261
self.end.fill(-1)
260262

261-
self.build(index, win, l_closed, r_closed)
263+
self.build(index, win, left_closed, right_closed)
262264

263265
# max window size
264266
self.win = (self.end - self.start).max()
265267

266-
def build(self, ndarray[int64_t] index, int64_t win, bint l_closed,
267-
bint r_closed):
268+
def build(self, ndarray[int64_t] index, int64_t win, bint left_closed,
269+
bint right_closed):
268270

269271
cdef:
270272
ndarray[int64_t] start, end
@@ -277,9 +279,11 @@ cdef class VariableWindowIndexer(WindowIndexer):
277279

278280
start[0] = 0
279281

280-
if r_closed: # right endpoint is closed
282+
# right endpoint is closed
283+
if right_closed:
281284
end[0] = 1
282-
else: # right endpoint is open
285+
# right endpoint is open
286+
else:
283287
end[0] = 0
284288

285289
with nogil:
@@ -290,7 +294,8 @@ cdef class VariableWindowIndexer(WindowIndexer):
290294
end_bound = index[i]
291295
start_bound = index[i] - win
292296

293-
if l_closed: # left endpoint is closed
297+
# left endpoint is closed
298+
if left_closed:
294299
start_bound -= 1
295300

296301
# advance the start bound until we are
@@ -309,7 +314,7 @@ cdef class VariableWindowIndexer(WindowIndexer):
309314
end[i] = end[i - 1]
310315

311316
# right endpoint is open
312-
if not r_closed:
317+
if not right_closed:
313318
end[i] -= 1
314319

315320

@@ -325,7 +330,8 @@ def get_window_indexer(input, win, minp, index, closed,
325330
minp: integer, minimum periods
326331
index: 1d ndarray, optional
327332
index to the input array
328-
closed: 'right', 'left', 'both', 'neither'
333+
closed: string, default 'right'
334+
{'right', 'left', 'both', 'neither'}
329335
window endpoint closedness
330336
floor: optional
331337
unit for flooring the unit
@@ -343,26 +349,26 @@ def get_window_indexer(input, win, minp, index, closed,
343349
"""
344350

345351
cdef:
346-
bint l_closed = False
347-
bint r_closed = False
352+
bint left_closed = False
353+
bint right_closed = False
348354

349355
assert closed in ['right', 'left', 'both', 'neither']
350356

351357
if closed in ['right', 'both']:
352-
r_closed = True
358+
right_closed = True
353359

354360
if closed in ['left', 'both']:
355-
l_closed = True
361+
left_closed = True
356362

357363
if index is not None:
358-
indexer = VariableWindowIndexer(input, win, minp, index, l_closed,
359-
r_closed)
364+
indexer = VariableWindowIndexer(input, win, minp, index, left_closed,
365+
right_closed)
360366
elif use_mock:
361367
indexer = MockFixedWindowIndexer(input, win, minp, index, floor,
362-
l_closed, r_closed)
368+
left_closed, right_closed)
363369
else:
364-
indexer = FixedWindowIndexer(input, win, minp, index, floor, l_closed,
365-
r_closed)
370+
indexer = FixedWindowIndexer(input, win, minp, index, floor, left_closed,
371+
right_closed)
366372
return indexer.get_data()
367373

368374
# ----------------------------------------------------------------------

pandas/tests/test_window.py

+3
Original file line numberDiff line numberDiff line change
@@ -3386,6 +3386,9 @@ def test_min_periods(self):
33863386
tm.assert_frame_equal(result, expected)
33873387

33883388
def test_closed(self):
3389+
3390+
# xref GH13965
3391+
33893392
df = DataFrame({'A': [1] * 5},
33903393
index=[pd.Timestamp('20130101 09:00:01'),
33913394
pd.Timestamp('20130101 09:00:02'),

0 commit comments

Comments
 (0)