Skip to content

Commit 0e8e65c

Browse files
carlosdanielcsantosjreback
authored andcommitted
Adding doc-strings and PEP8 corrections
Also, adding whatsnew entry
1 parent 5eaf3b4 commit 0e8e65c

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ To convert a ``SparseDataFrame`` back to sparse SciPy matrix in COO format, you
319319
Other Enhancements
320320
^^^^^^^^^^^^^^^^^^
321321

322+
- ``DataFrame.rolling()`` now accepts the parameter ``closed='right'|'left'|'both'|'neither'`` to choose the rolling window endpoint closedness. (:issue:`13965`)
322323
- Integration with the ``feather-format``, including a new top-level ``pd.read_feather()`` and ``DataFrame.to_feather()`` method, see :ref:`here <io.feather>`.
323324
- ``Series.str.replace()`` now accepts a callable, as replacement, which is passed to ``re.sub`` (:issue:`15055`)
324325
- ``Series.str.replace()`` now accepts a compiled regular expression as a pattern (:issue:`15446`)

pandas/core/window.py

-1
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,6 @@ def apply(self, func, args=(), kwargs={}):
800800
window = self._get_window()
801801
offset = _offset(window, self.center)
802802
index, indexi = self._get_index()
803-
closed = self.closed
804803

805804
def f(arg, window, min_periods, closed):
806805
minp = _use_window(min_periods, window)

pandas/core/window.pyx

+21-8
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ cdef class MockFixedWindowIndexer(WindowIndexer):
158158
index of the input
159159
floor: optional
160160
unit for flooring
161+
l_closed: bint
162+
left endpoint closedness
163+
r_closed: bint
164+
right endpoint closedness
161165
162166
"""
163167
def __init__(self, ndarray input, int64_t win, int64_t minp,
@@ -192,6 +196,10 @@ cdef class FixedWindowIndexer(WindowIndexer):
192196
index of the input
193197
floor: optional
194198
unit for flooring the unit
199+
l_closed: bint
200+
left endpoint closedness
201+
r_closed: bint
202+
right endpoint closedness
195203
196204
"""
197205
def __init__(self, ndarray input, int64_t win, int64_t minp,
@@ -231,10 +239,14 @@ cdef class VariableWindowIndexer(WindowIndexer):
231239
min number of obs in a window to consider non-NaN
232240
index: ndarray
233241
index of the input
242+
l_closed: bint
243+
left endpoint closedness
244+
r_closed: bint
245+
right endpoint closedness
234246
235247
"""
236248
def __init__(self, ndarray input, int64_t win, int64_t minp,
237-
ndarray index, bint l_closed=False, bint r_closed=True):
249+
ndarray index, bint l_closed, bint r_closed):
238250

239251
self.is_variable = 1
240252
self.N = len(index)
@@ -251,9 +263,8 @@ cdef class VariableWindowIndexer(WindowIndexer):
251263
# max window size
252264
self.win = (self.end - self.start).max()
253265

254-
255266
def build(self, ndarray[int64_t] index, int64_t win, bint l_closed,
256-
bint r_closed):
267+
bint r_closed):
257268

258269
cdef:
259270
ndarray[int64_t] start, end
@@ -266,9 +277,9 @@ cdef class VariableWindowIndexer(WindowIndexer):
266277

267278
start[0] = 0
268279

269-
if r_closed: # right endpoint is closed
280+
if r_closed: # right endpoint is closed
270281
end[0] = 1
271-
else: # right endpoint is open
282+
else: # right endpoint is open
272283
end[0] = 0
273284

274285
with nogil:
@@ -279,7 +290,7 @@ cdef class VariableWindowIndexer(WindowIndexer):
279290
end_bound = index[i]
280291
start_bound = index[i] - win
281292

282-
if l_closed: # left endpoint is closed
293+
if l_closed: # left endpoint is closed
283294
start_bound -= 1
284295

285296
# advance the start bound until we are
@@ -314,6 +325,8 @@ def get_window_indexer(input, win, minp, index, closed,
314325
minp: integer, minimum periods
315326
index: 1d ndarray, optional
316327
index to the input array
328+
closed: 'right', 'left', 'both', 'neither'
329+
window endpoint closedness
317330
floor: optional
318331
unit for flooring the unit
319332
use_mock: boolean, default True
@@ -1024,8 +1037,8 @@ def roll_median_c(ndarray[float64_t] input, int64_t win, int64_t minp,
10241037
object index, object closed):
10251038
cdef:
10261039
double val, res, prev
1027-
bint err=0, is_variable
1028-
int ret=0
1040+
bint err = 0, is_variable
1041+
int ret = 0
10291042
skiplist_t *sl
10301043
Py_ssize_t i, j
10311044
int64_t nobs = 0, N, s, e

pandas/tests/test_window.py

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

33883388
def test_closed(self):
3389-
df = DataFrame({'A': [1]*5},
3390-
index = [pd.Timestamp('20130101 09:00:01'),
3391-
pd.Timestamp('20130101 09:00:02'),
3392-
pd.Timestamp('20130101 09:00:03'),
3393-
pd.Timestamp('20130101 09:00:04'),
3394-
pd.Timestamp('20130101 09:00:06')])
3389+
df = DataFrame({'A': [1] * 5},
3390+
index=[pd.Timestamp('20130101 09:00:01'),
3391+
pd.Timestamp('20130101 09:00:02'),
3392+
pd.Timestamp('20130101 09:00:03'),
3393+
pd.Timestamp('20130101 09:00:04'),
3394+
pd.Timestamp('20130101 09:00:06')])
33953395

33963396
# closed must be 'right', 'left', 'both', 'neither'
33973397
with self.assertRaises(ValueError):

0 commit comments

Comments
 (0)