-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: rolling aggregations not checking monotonic index when grouping by #34617
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
Comments
Btw, before posting I check for similar issues and found this old thread #15130 I'm not sure why there is no need to validate monotonicity when groupby-rolling? |
Update. It seems that the NAs are the issues. When grouping by the groups seem to be resorted according to the index to yield the right aggregation.
Maybe there should be a check on the index to make sure there are no NAs? Or let the user know in the documentation? |
@frd-glovo in your initial post you have two expected outputs. Which one is the correct one, and can you remove the other? Or is the other one the actual output? Is a fair summary to say that that rolling aggregations don't correctly handle missing data? Does this just affect groupby().rolling, or rolling as well? |
cc @mroeschke I think this should raise like a simle rolling operation and not return a result. Is that right? |
@phofl yes I would expect this to raise like |
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.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Problem description
When using a rolling window on a timestamp index + a group by, there is no validation about the monotonicity of the index. This can lead to unexpected behaviours, as the value of the calculation can change if the index is not monotonic.
Expected Output
Output:
c a
1 2020-06-01 12:00:00 1.0
2020-06-01 12:30:00 3.0
2020-06-01 13:00:00 6.0
2020-06-01 14:00:00 10.0
NaT 15.0
Expected (correct) output:
c a
1 2020-06-01 12:00:00 1.0
2020-06-01 12:30:00 3.0
2020-06-01 13:00:00 5.0
2020-06-01 14:00:00 4.0
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.5.final.0
python-bits : 64
OS : Linux
OS-release : 4.9.184-linuxkit
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.0.4
numpy : 1.18.0
pytz : 2019.1
dateutil : 2.7.5
pip : 19.3.1
setuptools : 41.4.0
Cython : None
pytest : 4.1.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : 0.9.3
psycopg2 : 2.8.2 (dt dec pq3 ext lo64)
jinja2 : 2.10.1
IPython : 7.11.1
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.1.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 4.1.1
pyxlsb : None
s3fs : None
scipy : 1.2.0
sqlalchemy : 1.2.16
tables : None
tabulate : 0.8.3
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: