Skip to content

BUG: TimeStamp index rolling problems #46808

Closed
@mIgLLL

Description

@mIgLLL

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

data = pd.date_range(start='1/1/2018', periods=8).to_frame(name='date')
data['symbol'] = 1

data = data.append(data)
data.iloc[8:,1] = 2

data['value'] = 1

## total 16 days ( ValueError: index must be monotonic )
roll_mean = data.groupby('symbol')['value'].rolling('2d').mean()

## only second 8 days (Only globally monotonic index worked)
roll_mean = data.iloc[8:,:].groupby('symbol')['value'].rolling('2d').mean()

Issue Description

There is a problem that the rolling function requires the index to be monotonic in the newest version of pandas (1.4.1). It start to require a globally monotonic index for rolling function, which is quite unreasonable for timestamp index. Panel data are used quite commonly! The global monotonic requirement should instead be taken of by " within group monotonic".

Expected Behavior

return to the previous "within-group monotonic".

Installed Versions

Replace this line with the output of pd.show_versions()

  • I have reinstall the pandas as 1.3.5 to avoid this problem, 1.4.1 is the version that cause this problem.

INSTALLED VERSIONS

commit : 66e3805
python : 3.9.12.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19042
machine : AMD64
processor : Intel64 Family 6 Model 165 Stepping 2, GenuineIntel
byteorder : little
LC_ALL : None
LANG : zh_CN
LOCALE : Chinese (Simplified)_China.936

pandas : 1.3.5
numpy : 1.20.3
pytz : 2021.3
dateutil : 2.8.2
pip : 21.2.4
setuptools : 61.2.0
Cython : 0.29.28
pytest : 7.1.1
hypothesis : None
sphinx : 4.4.0
blosc : None
feather : None
xlsxwriter : 3.0.3
lxml.etree : 4.8.0
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 8.2.0
pandas_datareader: 0.10.0
bs4 : 4.10.0
bottleneck : 1.3.4
fsspec : 2022.02.0
fastparquet : 0.8.0
gcsfs : None
matplotlib : 3.5.1
numexpr : 2.8.1
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : 7.0.0
pyxlsb : None
s3fs : None
scipy : 1.7.3
sqlalchemy : 1.4.32
tables : 3.6.1
tabulate : 0.8.9
xarray : None
xlrd : 2.0.1
xlwt : 1.3.0
numba : 0.54.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions