Skip to content

Commit 6e46099

Browse files
author
Chang She
committed
BUG: buffer access out of bounds with roll_generic on empty
1 parent d1e3e1b commit 6e46099

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pandas/src/moments.pyx

+3
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,9 @@ def roll_generic(ndarray[float64_t, cast=True] input, int win,
696696
buf = <float64_t*> input.data
697697

698698
n = len(input)
699+
if n == 0:
700+
return input
701+
699702
minp = _check_minp(minp, n)
700703
output = np.empty(n, dtype=float)
701704
counts = roll_sum(np.isfinite(input).astype(float), win, minp)

pandas/stats/tests/test_moments.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import numpy as np
99

1010
from pandas import Series, DataFrame, bdate_range
11-
from pandas.util.testing import assert_almost_equal
11+
from pandas.util.testing import assert_almost_equal, assert_series_equal
1212
import pandas.core.datetools as datetools
1313
import pandas.stats.moments as mom
1414
import pandas.util.testing as tm
@@ -73,6 +73,9 @@ def alt(x):
7373
self._check_moment_func(f, alt)
7474

7575
def test_rolling_apply(self):
76+
ser = Series([])
77+
assert_series_equal(ser, mom.rolling_apply(ser, 10, lambda x:x.mean()))
78+
7679
def roll_mean(x, window, min_periods=None, freq=None):
7780
return mom.rolling_apply(x, window,
7881
lambda x: x[np.isfinite(x)].mean(),

0 commit comments

Comments
 (0)