8000 BUG: Rolling apply on DataFrame with Datetime index returns NaN by FXocena · Pull Request #17156 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: Rolling apply on DataFrame with Datetime index returns NaN #17156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 10, 2017
Prev Previous commit
Next Next commit
clean up whatsnew, parametrize tests, fix some whitespace issues
  • Loading branch information
jreback committed Aug 8, 2017
commit 9c5e1c16bd1510188bfee95d90e1e8220e5b043a
3 changes: 1 addition & 2 deletions doc/source/whatsnew/v0.21.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@ Groupby/Resample/Rolling
- Bug in :func:`infer_freq` causing indices with 2-day gaps during the working week to be wrongly inferred as business daily (:issue:`16624`)
- Bug in ``.rolling(...).quantile()`` which incorrectly used different defaults than :func:`Series.quantile()` and :func:`DataFrame.quantile()` (:issue:`9413`, :issue:`16211`)
- Bug in ``groupby.transform()`` that would coerce boolean dtypes back to float (:issue:`16875`)
- Bug in ``.rolling(...).apply(...)`` where when rolling apply on DataFrame
with Datetime index and min_periods set to be greater than 1 (:issue:`15305`)
- Bug in ``.rolling(...).apply(...)`` with a ``DataFrame`` with a ``DatetimeIndex``, a ``window`` of a timedelta-convertible and ``min_periods >= 1` (:issue:`15305`)

Sparse
^^^^^^
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/window.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1427,11 +1427,11 @@ def roll_generic(ndarray[float64_t, cast=True] input,
n = len(input)
if n == 0:
return input

counts = roll_sum(np.concatenate([np.isfinite(input).astype(float),
np.array([0.] * offset)]),
win, minp, index, closed)[offset:]

start, end, N, win, minp, is_variable = get_window_indexer(input, win,
minp, index,
closed,
Expand Down
15 changes: 8 additions & 7 deletions pandas/tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,9 @@ def test_constructor_with_timedelta_window(self):
expected = df.rolling('3D').sum()
tm.assert_frame_equal(result, expected)

def test_constructor_with_timedelta_window_and_minperiods(self):
@pytest.mark.parametrize(
'window', [timedelta(days=3), pd.Timedelta(days=3), '3D'])
def test_constructor_with_timedelta_window_and_minperiods(self, window):
# GH 15305
n = 10
df = pd.DataFrame({'value': np.arange(n)},
Expand All @@ -435,12 +437,11 @@ def test_constructor_with_timedelta_window_and_minperiods(self):
index=pd.date_range('2017-08-08',
periods=n,
freq="D"))
for window in [timedelta(days=3), pd.Timedelta(days=3), '3D']:
result_roll_sum = df.rolling(window=window, min_periods=2).sum()
result_roll_generic = df.rolling(window=window,
min_periods=2).apply(sum)
tm.assert_frame_equal(result_roll_sum, expected)
tm.assert_frame_equal(result_roll_generic, expected)
result_roll_sum = df.rolling(window=window, min_periods=2).sum()
result_roll_generic = df.rolling(window=window,
min_periods=2).apply(sum)
tm.assert_frame_equal(result_roll_sum, expected)
tm.assert_frame_equal(result_roll_generic, expected)

def test_numpy_compat(self):
# see gh-12811
Expand Down
0