Skip to content

Commit b30a50f

Browse files
committed
BUG: groupby-rolling with a timedelta
closes pandas-dev#13966 xref to pandas-dev#15130, closed by pandas-dev#15175
1 parent f562308 commit b30a50f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

doc/source/whatsnew/v0.20.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ Groupby/Resample/Rolling
16771677
- Bug in ``.groupby(..).resample()`` when passed the ``on=`` kwarg. (:issue:`15021`)
16781678
- Properly set ``__name__`` and ``__qualname__`` for ``Groupby.*`` functions (:issue:`14620`)
16791679
- Bug in ``GroupBy.get_group()`` failing with a categorical grouper (:issue:`15155`)
1680-
- Bug in ``.groupby(...).rolling(...)`` when ``on`` is specified and using a ``DatetimeIndex`` (:issue:`15130`)
1680+
- Bug in ``.groupby(...).rolling(...)`` when ``on`` is specified and using a ``DatetimeIndex`` (:issue:`15130`, :issue:`13966`)
16811681
- Bug in groupby operations with ``timedelta64`` when passing ``numeric_only=False`` (:issue:`5724`)
16821682
- Bug in ``groupby.apply()`` coercing ``object`` dtypes to numeric types, when not all values were numeric (:issue:`14423`, :issue:`15421`, :issue:`15670`)
16831683
- Bug in ``resample``, where a non-string ``loffset`` argument would not be applied when resampling a timeseries (:issue:`13218`)

pandas/tests/test_window.py

+18
Original file line numberDiff line numberDiff line change
@@ -3782,3 +3782,21 @@ def test_groupby_monotonic(self):
37823782
lambda x: x.rolling('180D')['amount'].sum())
37833783
result = df.groupby('name').rolling('180D', on='date')['amount'].sum()
37843784
tm.assert_series_equal(result, expected)
3785+
3786+
def test_non_monotonic(self):
3787+
# GH 13966 (similar to #15130, closed by #15175)
3788+
3789+
dates = pd.date_range(start='2016-01-01 09:30:00',
3790+
periods=20, freq='s')
3791+
df = pd.DataFrame({'A': [1] * 20 + [2] * 12 + [3] * 8,
3792+
'B': np.concatenate((dates, dates)),
3793+
'C': np.arange(40)})
3794+
3795+
result = df.groupby('A').rolling('4s', on='B').C.mean()
3796+
expected = df.set_index('B').groupby('A').apply(
3797+
lambda x: x.rolling('4s')['C'].mean())
3798+
tm.assert_series_equal(result, expected)
3799+
3800+
df2 = df.sort_values('B')
3801+
result = df2.groupby('A').rolling('4s', on='B').C.mean()
3802+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)