Skip to content

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

Closed
@cragod

Description

@cragod
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNumeric OperationsArithmetic, Comparison, and Logical operationsRegressionFunctionality that used to work in a prior pandas versionWindowrolling, ewma, expanding

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions