Skip to content

Commit f736ca2

Browse files
committed
The roll_quantile function in window.pyx now raises a ValueError when the quantile value is not in [0.0, 1.0]
1 parent f62e8f2 commit f736ca2

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

pandas/tests/test_window.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ def test_rolling_max(self):
10631063
window=3, min_periods=5)
10641064

10651065
def test_rolling_quantile(self):
1066-
qs = [.1, .5, .9]
1066+
qs = [0.0, .1, .5, .9, 1.0]
10671067

10681068
def scoreatpercentile(a, per):
10691069
values = np.sort(a, axis=0)
@@ -1084,6 +1084,12 @@ def alt(x):
10841084

10851085
self._check_moment_func(f, alt, name='quantile', quantile=q)
10861086

1087+
self.assertRaises(ValueError, mom.rolling_quantile,
1088+
np.array([1, 2, 3]), window=3, quantile=-0.1)
1089+
1090+
self.assertRaises(ValueError, mom.rolling_quantile,
1091+
np.array([1, 2, 3]), window=3, quantile=10)
1092+
10871093
def test_rolling_apply(self):
10881094
# suppress warnings about empty slices, as we are deliberately testing
10891095
# with a 0-length Series

pandas/window.pyx

+5-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ cdef class WindowIndexer:
134134
bint is_variable
135135

136136
def get_data(self):
137-
return (self.start, self.end, <int64_t>self.N,
138-
<int64_t>self.win, <int64_t>self.minp,
137+
return (self.start, self.end, <int64_t>self.N,
138+
<int64_t>self.win, <int64_t>self.minp,
139139
self.is_variable)
140140

141141

@@ -1285,6 +1285,9 @@ def roll_quantile(ndarray[float64_t, cast=True] input, int64_t win,
12851285
ndarray[int64_t] start, end
12861286
ndarray[double_t] output
12871287

1288+
if quantile < 0.0 or quantile > 1.0:
1289+
raise ValueError("quantile value {0} not in [0, 1]".format(quantile))
1290+
12881291
# we use the Fixed/Variable Indexer here as the
12891292
# actual skiplist ops outweigh any window computation costs
12901293
start, end, N, win, minp, is_variable = get_window_indexer(

0 commit comments

Comments
 (0)