Open
Description
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
(optional) I have confirmed this bug exists on the master branch of pandas.
xref #43355
In [1]: df = pd.DataFrame(
...: {
...: "id": ["a", "a", "b", "b", "b"],
...: "timestamp": pd.date_range("2021-9-1", periods=5, freq="H"),
...: "y": range(5),
...: }
...: )
...: df
Out[1]:
id timestamp y
0 a 2021-09-01 00:00:00 0
1 a 2021-09-01 01:00:00 1
2 b 2021-09-01 02:00:00 2
3 b 2021-09-01 03:00:00 3
4 b 2021-09-01 04:00:00 4
In [2]: grp = df.groupby("id").rolling("1H", on="timestamp")
...: grp.count().index
Out[2]:
MultiIndex([('a', 0),
('a', 1),
('b', 2),
('b', 3),
('b', 4)],
names=['id', None])
In [4]: grp["y"].count().index
Out[4]:
MultiIndex([('a', '2021-09-01 00:00:00'),
('a', '2021-09-01 01:00:00'),
('b', '2021-09-01 02:00:00'),
('b', '2021-09-01 03:00:00'),
('b', '2021-09-01 04:00:00')],
names=['id', 'timestamp'])
According to the on
documentation
For a DataFrame, a datetime-like column or Index level on which to calculate the rolling window, rather than the DataFrame’s index. Provided integer column is ignored and excluded from result since an integer index is not used to calculate the rolling window.
Though the docs specifically states this applies to a DataFrame
, this inconsistency seems confusing to users and could be possible for a DataFrame
and Series
result to have the same index result