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

REGR: incorrect results with std on rolling window since 1.2.0 #38874

Closed
2 of 3 tasks
cragod opened this issue Jan 1, 2021 · 6 comments
Closed
2 of 3 tasks

REGR: incorrect results with std on rolling window since 1.2.0 #38874

cragod opened this issue Jan 1, 2021 · 6 comments
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations Regression Functionality that used to work in a prior pandas version Window rolling, ewma, expanding

Comments

@cragod
Copy link

cragod commented Jan 1, 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.


Code Sample

import pandas as pd
import numpy as np

df = pd.DataFrame({'A': [1e-8, -1.1e-8, 1.2e-8, -1.1e-8] * 5})
df['std'] = df['A'].rolling(10).std(ddof=0)
print(df)

Problem description

when i ran above code in 1.2.0, the output is:

               A               std
0   1.000000e-08  NaN
1  -1.100000e-08  NaN
2   1.200000e-08  NaN
3  -1.100000e-08  NaN
4   1.000000e-08  NaN
5  -1.100000e-08  NaN
6   1.200000e-08  NaN
7  -1.100000e-08  NaN
8   1.000000e-08  NaN
9  -1.100000e-08  0.0
10  1.200000e-08  0.0
11 -1.100000e-08  0.0
12  1.000000e-08  0.0
13 -1.100000e-08  0.0
14  1.200000e-08  0.0
15 -1.100000e-08  0.0
16  1.000000e-08  0.0
17 -1.100000e-08  0.0
18  1.200000e-08  0.0
19 -1.100000e-08  0.0

Expected Output

ran in 1.1.5:

               A           std
0   1.000000e-08           NaN
1  -1.100000e-08           NaN
2   1.200000e-08           NaN
3  -1.100000e-08           NaN
4   1.000000e-08           NaN
5  -1.100000e-08           NaN
6   1.200000e-08           NaN
7  -1.100000e-08           NaN
8   1.000000e-08           NaN
9  -1.100000e-08  1.092200e-08
10  1.200000e-08  1.112160e-08
11 -1.100000e-08  1.112160e-08
12  1.000000e-08  1.092200e-08
13 -1.100000e-08  1.092200e-08
14  1.200000e-08  1.112160e-08
15 -1.100000e-08  1.112160e-08
16  1.000000e-08  1.092200e-08
17 -1.100000e-08  1.092200e-08
18  1.200000e-08  1.112160e-08
19 -1.100000e-08  1.112160e-08

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 3e89b4c
python : 3.7.5.final.0
python-bits : 64
OS : Darwin
OS-release : 20.2.0
Version : Darwin Kernel Version 20.2.0: Wed Dec 2 20:39:59 PST 2020; root:xnu-7195.60.75~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : zh_CN.UTF-8
LOCALE : zh_CN.UTF-8

pandas : 1.2.0
numpy : 1.18.2
pytz : 2019.3
dateutil : 2.8.1
pip : 20.3.3
setuptools : 41.2.0
Cython : None
pytest : 5.4.1
hypothesis : None
sphinx : 1.8.5
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.5.2
html5lib : None
pymysql : 0.9.3
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.11.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.15
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@cragod cragod added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 1, 2021
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Jan 1, 2021
@simonjayhawkins
Copy link
Member

Thanks @cragod for the report.

first bad commit: [846cff9] REF: Remove rolling window fixed algorithms (#36567) cc @mroeschke

@simonjayhawkins simonjayhawkins added Numeric Operations Arithmetic, Comparison, and Logical operations Window rolling, ewma, expanding and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 1, 2021
@simonjayhawkins simonjayhawkins added this to the 1.2.1 milestone Jan 1, 2021
@simonjayhawkins simonjayhawkins added the Regression Functionality that used to work in a prior pandas version label Jan 1, 2021
@simonjayhawkins simonjayhawkins changed the title BUG: 1.2.0 std issue REGR: incorrect results with std on rolling window since 1.2.0 Jan 1, 2021
@phofl
Copy link
Member

phofl commented Jan 1, 2021

Isn't the output in 1.1.5 wrong too?

Edit; Forget it, was running var not std...

@phofl
Copy link
Member

phofl commented Jan 1, 2021

This has the same underlying cause as mentioned in #37051 and non trivial to fix

@mroeschke
Copy link
Member

Thanks for the report @cragod.

As @phofl mentioned, the cause of this is #37051. Let's track this issue in that thread, so going to close this as a duplicate. Happy to have eyes on that issue!

@simonjayhawkins
Copy link
Member

This has the same underlying cause as mentioned in #37051 and non trivial to fix

"non trivial" sounds to me alot like not suitable for backport.

re-opening this issue for now for discussion on how to resolve the issue on the 1.2.x branch.

@MarcoGorelli MarcoGorelli added the Needs Discussion Requires discussion from core team before further action label Jan 3, 2021
@jreback
Copy link
Contributor

jreback commented Jan 16, 2021

we cannot handle this as a backport and its non-trivial to fix this. that said this is an edge case so won't fix for 1.2.x

@jreback jreback closed this as completed Jan 16, 2021
@simonjayhawkins simonjayhawkins removed the Needs Discussion Requires discussion from core team before further action label Jan 16, 2021
@simonjayhawkins simonjayhawkins removed this from the 1.2.1 milestone Jan 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations Regression Functionality that used to work in a prior pandas version Window rolling, ewma, expanding
Projects
None yet
Development

No branches or pull requests

6 participants