Skip to content

Commit 5eaf3b4

Browse files
carlosdanielcsantosjreback
authored andcommitted
str closed -> object closed
Adding test of assert for closed parameter Adding assert for closed parameter in get_window_indexer
1 parent 2cf6804 commit 5eaf3b4

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

pandas/core/window.pyx

+13-14
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,7 @@ def get_window_indexer(input, win, minp, index, closed,
333333
bint l_closed = False
334334
bint r_closed = False
335335

336-
if closed not in ['right', 'left', 'both', 'neither']:
337-
closed = 'right'
336+
assert closed in ['right', 'left', 'both', 'neither']
338337

339338
if closed in ['right', 'both']:
340339
r_closed = True
@@ -359,7 +358,7 @@ def get_window_indexer(input, win, minp, index, closed,
359358

360359

361360
def roll_count(ndarray[double_t] input, int64_t win, int64_t minp,
362-
object index, closed='right'):
361+
object index, object closed):
363362
cdef:
364363
double val, count_x = 0.0
365364
int64_t s, e, nobs, N
@@ -440,7 +439,7 @@ cdef inline void remove_sum(double val, int64_t *nobs, double *sum_x) nogil:
440439

441440

442441
def roll_sum(ndarray[double_t] input, int64_t win, int64_t minp,
443-
object index, str closed):
442+
object index, object closed):
444443
cdef:
445444
double val, prev_x, sum_x = 0
446445
int64_t s, e
@@ -556,7 +555,7 @@ cdef inline void remove_mean(double val, Py_ssize_t *nobs, double *sum_x,
556555

557556

558557
def roll_mean(ndarray[double_t] input, int64_t win, int64_t minp,
559-
object index, str closed):
558+
object index, object closed):
560559
cdef:
561560
double val, prev_x, result, sum_x = 0
562561
int64_t s, e
@@ -681,7 +680,7 @@ cdef inline void remove_var(double val, double *nobs, double *mean_x,
681680

682681

683682
def roll_var(ndarray[double_t] input, int64_t win, int64_t minp,
684-
object index, str closed, int ddof=1):
683+
object index, object closed, int ddof=1):
685684
"""
686685
Numerically stable implementation using Welford's method.
687686
"""
@@ -824,7 +823,7 @@ cdef inline void remove_skew(double val, int64_t *nobs, double *x, double *xx,
824823

825824

826825
def roll_skew(ndarray[double_t] input, int64_t win, int64_t minp,
827-
object index, str closed):
826+
object index, object closed):
828827
cdef:
829828
double val, prev
830829
double x = 0, xx = 0, xxx = 0
@@ -952,7 +951,7 @@ cdef inline void remove_kurt(double val, int64_t *nobs, double *x, double *xx,
952951

953952

954953
def roll_kurt(ndarray[double_t] input, int64_t win, int64_t minp,
955-
object index, str closed):
954+
object index, object closed):
956955
cdef:
957956
double val, prev
958957
double x = 0, xx = 0, xxx = 0, xxxx = 0
@@ -1022,7 +1021,7 @@ def roll_kurt(ndarray[double_t] input, int64_t win, int64_t minp,
10221021

10231022

10241023
def roll_median_c(ndarray[float64_t] input, int64_t win, int64_t minp,
1025-
object index, str closed):
1024+
object index, object closed):
10261025
cdef:
10271026
double val, res, prev
10281027
bint err=0, is_variable
@@ -1148,7 +1147,7 @@ cdef inline numeric calc_mm(int64_t minp, Py_ssize_t nobs,
11481147

11491148

11501149
def roll_max(ndarray[numeric] input, int64_t win, int64_t minp,
1151-
object index, str closed):
1150+
object index, object closed):
11521151
"""
11531152
Moving max of 1d array of any numeric type along axis=0 ignoring NaNs.
11541153
@@ -1168,7 +1167,7 @@ def roll_max(ndarray[numeric] input, int64_t win, int64_t minp,
11681167

11691168

11701169
def roll_min(ndarray[numeric] input, int64_t win, int64_t minp,
1171-
object index, str closed):
1170+
object index, object closed):
11721171
"""
11731172
Moving max of 1d array of any numeric type along axis=0 ignoring NaNs.
11741173
@@ -1185,7 +1184,7 @@ def roll_min(ndarray[numeric] input, int64_t win, int64_t minp,
11851184

11861185

11871186
cdef _roll_min_max(ndarray[numeric] input, int64_t win, int64_t minp,
1188-
object index, str closed, bint is_max):
1187+
object index, object closed, bint is_max):
11891188
"""
11901189
Moving min/max of 1d array of any numeric type along axis=0
11911190
ignoring NaNs.
@@ -1312,7 +1311,7 @@ cdef _roll_min_max(ndarray[numeric] input, int64_t win, int64_t minp,
13121311

13131312

13141313
def roll_quantile(ndarray[float64_t, cast=True] input, int64_t win,
1315-
int64_t minp, object index, str closed,
1314+
int64_t minp, object index, object closed,
13161315
double quantile):
13171316
"""
13181317
O(N log(window)) implementation using skip list
@@ -1376,7 +1375,7 @@ def roll_quantile(ndarray[float64_t, cast=True] input, int64_t win,
13761375

13771376

13781377
def roll_generic(ndarray[float64_t, cast=True] input,
1379-
int64_t win, int64_t minp, object index, str closed,
1378+
int64_t win, int64_t minp, object index, object closed,
13801379
int offset, object func,
13811380
object args, object kwargs):
13821381
cdef:

pandas/tests/test_window.py

+4
Original file line numberDiff line numberDiff line change
@@ -3393,6 +3393,10 @@ def test_closed(self):
33933393
pd.Timestamp('20130101 09:00:04'),
33943394
pd.Timestamp('20130101 09:00:06')])
33953395

3396+
# closed must be 'right', 'left', 'both', 'neither'
3397+
with self.assertRaises(ValueError):
3398+
self.regular.rolling(window='2s', closed="blabla")
3399+
33963400
expected = df.copy()
33973401
expected["A"] = [1.0, 2, 2, 2, 1]
33983402
result = df.rolling('2s', closed='right').sum()

0 commit comments

Comments
 (0)