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: rolling with uneven nanosecond window have wrong results #43997

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

BUG: rolling with uneven nanosecond window have wrong results #43997

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

Comments

@rosagold
Copy link
Contributor

rosagold commented Oct 12, 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

index = pd.date_range("2020", periods=4, freq="1ns")
df = pd.Series([1, 1, 1, 1], index=index, dtype=float)
result = df.rolling('3ns', closed='neither', center=True).sum()

print(result)
# 2020-01-01 00:00:00.000000000    1.0
# 2020-01-01 00:00:00.000000001    1.0
# 2020-01-01 00:00:00.000000002    1.0
# 2020-01-01 00:00:00.000000003    1.0
# Freq: N, dtype: float64

Issue Description

Rolling with smallest possible resolution (currently nanoseconds) centered windows and uneven nanoseconds produce wrong results.

Eg. rolling with a centered window='3ns', regardless of closed, should result in a forward facing and a backward facing window of 1.5ns, which is effectively a fwd/bwd facing window of 1ns with closed='both'.

btw. thats exactly the code change in the followup PR will introduce ;)

Expected Behavior

>>> result
2020-01-01 00:00:00.000000000    2.0
2020-01-01 00:00:00.000000001    3.0
2020-01-01 00:00:00.000000002    3.0
2020-01-01 00:00:00.000000003    2.0
Freq: N, dtype: float64

Installed Versions

INSTALLED VERSIONS

commit : 075ec87
python : 3.8.12.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.4.0.dev0+869.g075ec87643
numpy : 1.21.2
pytz : 2021.1
dateutil : 2.8.2
pip : 21.2.4
setuptools : 58.2.0
Cython : 0.29.24
pytest : 6.2.5
hypothesis : 6.23.1
sphinx : 4.2.0
blosc : None
feather : None
xlsxwriter : 3.0.1
lxml.etree : 4.6.3
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.28.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : 1.3.2
fsspec : 2021.10.0
fastparquet : 0.7.1
gcsfs : 2021.10.0
matplotlib : 3.4.3
numexpr : 2.7.3
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : 5.0.0
pyxlsb : None
s3fs : 2021.10.0
scipy : 1.7.1
sqlalchemy : 1.4.25
tables : 3.6.1
tabulate : 0.8.9
xarray : 0.18.2
xlrd : 2.0.1
xlwt : 1.3.0
numba : 0.53.1

@rosagold rosagold added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 12, 2021
@rosagold rosagold changed the title BUG: BUG: rolling with uneven nanoseconds have wrong results Oct 12, 2021
@rosagold rosagold changed the title BUG: rolling with uneven nanoseconds have wrong results BUG: rolling with uneven nanosecond window have wrong results Oct 12, 2021
@mroeschke mroeschke removed the Needs Triage Issue that has not been reviewed by a pandas team member label Oct 13, 2021
@mroeschke mroeschke added this to the 1.4 milestone Oct 13, 2021
@mroeschke mroeschke added the Window rolling, ewma, expanding label Oct 13, 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.

2 participants