Skip to content

data frame rolling std return wrong result with large elements #28244

Closed
@KaneFu

Description

@KaneFu

Code Sample, a copy-pastable example if possible

arr = [9.54e+08, 6.225e-01, np.nan, 0, 1.14, 0]
arr = pd.DataFrame(arr)
print(arr.rolling(5,3).std())
###output
              0
0           NaN
1           NaN
2           NaN
3  5.507922e+08
4  4.770000e+08
5  0.000000e+00
#### Problem description

Expected output.iloc[5,0] = 0.551, as we can see the standeviation of last five elements shouldn't be zero. <br>
But if i change the first element from 9.54e+08 to 9.45e+07, the last standeviation is 0.816 which is still wrong. If i change the first element to 9.45e+5, everything is okay.  <br>
The first element should not affect the result since the window=5, but there seems to be a bug with large elements, and a magnitude of e+08 definitely will not overflow.  <br>
There must be some bugs.


#### Output of ``pd.show_versions()``

<details>

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Darwin
OS-release: 18.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.24.2
pytest: 3.0.7
pip: 19.2.1
setuptools: 36.4.0
Cython: 0.25.2
numpy: 1.13.1
scipy: 0.19.1
pyarrow: None
xarray: 0.12.3
IPython: 5.3.0
sphinx: 1.5.6
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 2.4.7
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml.etree: 3.7.3
bs4: 4.6.0
</details>

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugWindowrolling, ewma, expanding

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions