Skip to content
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

BUG: centered rolling on decreasing datetime-index inconsistency #43927

Closed
3 tasks done
rosagold opened this issue Oct 8, 2021 · 0 comments · Fixed by #43928
Closed
3 tasks done

BUG: centered rolling on decreasing datetime-index inconsistency #43927

rosagold opened this issue Oct 8, 2021 · 0 comments · Fixed by #43928
Labels
Bug Window rolling, ewma, expanding
Milestone

Comments

@rosagold
Copy link
Contributor

rosagold commented Oct 8, 2021

  • 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 master branch of pandas.

Reproducible Example

import pandas as pd
import numpy as np

index = pd.date_range('2020', periods=4, freq='s')

inc = pd.Series([1,1,1,1], index=index).rolling('3s', center=True).sum()
dec = pd.Series([1,1,1,1], index=index[::-1]).rolling('3s', center=True).sum()

assert np.all(inc.values == dec.values)

>>> inc
2020-01-01 00:00:00    2.0
2020-01-01 00:00:01    3.0
2020-01-01 00:00:02    3.0
2020-01-01 00:00:03    2.0
Freq: S, dtype: float64

>>> dec
2020-01-01 00:00:03    NaN
2020-01-01 00:00:02    3.0
2020-01-01 00:00:01    3.0
2020-01-01 00:00:00    2.0
Freq: -1S, dtype: float64

Issue Description

the first value is a NaN when rolling over a decreasing index with center=True, but it shouldnt. This happens for ever value of closed.

AFAIK, this comes from the cython implementation of calculate_valiable_window_bounds.

I prepared a MR for this.

Expected Behavior

no NaN as first value.

Installed Versions

INSTALLED VERSIONS

commit : 73c6825
python : 3.9.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-88-generic
Version : #99-Ubuntu SMP Thu Sep 23 17:29:00 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.3.3
numpy : 1.20.3
pytz : 2021.1
dateutil : 2.8.2
pip : 21.2.4
setuptools : 57.0.0
Cython : None
pytest : 6.2.5
hypothesis : 6.17.4
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 4.0.1
pyxlsb : None
s3fs : None
scipy : 1.7.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.54.0

@rosagold rosagold added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 8, 2021
@mroeschke mroeschke added Window rolling, ewma, expanding and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 8, 2021
@jreback jreback added this to the 1.4 milestone Oct 9, 2021
@rosagold rosagold mentioned this issue Oct 15, 2021
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants