Skip to content

BUG: rolling with time window does not always pick edge correctly #40002

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

Closed
2 of 3 tasks
ChiQiao opened this issue Feb 23, 2021 · 1 comment · Fixed by #40006
Closed
2 of 3 tasks

BUG: rolling with time window does not always pick edge correctly #40002

ChiQiao opened this issue Feb 23, 2021 · 1 comment · Fixed by #40006
Labels
Bug Window rolling, ewma, expanding
Milestone

Comments

@ChiQiao
Copy link

ChiQiao commented Feb 23, 2021

  • 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

data = pd.Series(range(1, 4), index=pd.date_range(start="2020-01-01", end="2020-01-03", freq="1d")).iloc[::-1]
data.rolling("1d", closed="left").sum()

Problem description

I'm expecting the result to be

2020-01-03   NaN
2020-01-02   3.0
2020-01-01   2.0
Freq: -1D, dtype: float64

but instead I get

2020-01-03   NaN
2020-01-02   NaN
2020-01-01   NaN
Freq: -1D, dtype: float64

This problem doesn't occur if window is int instead of offset, or if index is in ascending order.
For example:
data.rolling(1, closed="left").sum() yields

2020-01-03    NaN
2020-01-02    3.0
2020-01-01    2.0
Freq: -1D, dtype: float64

and

data = pd.Series(range(1, 4), index=pd.date_range(start="2020-01-01", end="2020-01-03", freq="1d"))
data.rolling("1d", closed="left").sum()

yields

2020-01-01    NaN
2020-01-02    1.0
2020-01-03    2.0
Freq: D, dtype: float64

Expected Output

2020-01-03   NaN
2020-01-02   3.0
2020-01-01   2.0
Freq: -1D, dtype: float64

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 9d598a5
python : 3.7.9.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : None.None

pandas : 1.2.1
numpy : 1.19.2
pytz : 2021.1
dateutil : 2.8.1
pip : 20.3.3
setuptools : 52.0.0.post20210125
Cython : 0.29.21
pytest : 6.2.2
hypothesis : None
sphinx : 3.4.3
blosc : None
feather : None
xlsxwriter : 1.3.7
lxml.etree : 4.6.2
html5lib : 1.1
pymysql : 1.0.2
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.20.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : 1.3.2
fsspec : 0.8.3
fastparquet : None
gcsfs : None
matplotlib : 3.3.2
numexpr : 2.7.2
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : 0.15.1
pyxlsb : None
s3fs : 0.4.2
scipy : 1.6.0
sqlalchemy : 1.3.23
tables : 3.6.1
tabulate : 0.8.7
xarray : 0.16.2
xlrd : 2.0.1
xlwt : 1.3.0
numba : 0.51.2

@ChiQiao ChiQiao added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 23, 2021
@phofl phofl added Window rolling, ewma, expanding and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 23, 2021
@jreback jreback added this to the 1.3 milestone Feb 24, 2021
@ChiQiao
Copy link
Author

ChiQiao commented Feb 24, 2021

Thanks @phofl for the quick fix!

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