Skip to content

rolling.sum() of zeros produce positive output w/ float64 #24208

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
someben opened this issue Dec 10, 2018 · 1 comment
Closed

rolling.sum() of zeros produce positive output w/ float64 #24208

someben opened this issue Dec 10, 2018 · 1 comment
Labels
Bug Duplicate Report Duplicate issue or pull request Numeric Operations Arithmetic, Comparison, and Logical operations Window rolling, ewma, expanding

Comments

@someben
Copy link
Contributor

someben commented Dec 10, 2018

Code Sample, a copy-pastable example if possible

import io

import numpy as np
import pandas as pd

def test_rolling_sum(float_type):
    err_df = pd.DataFrame([[
        123.0,
        0.0,
        1.123456789,
        0.0,
        0.0,
        0.0,
        0.0,
        0.0,
        0.0,
        0.0,
    ]], dtype=float_type).T
    assert err_df.rolling(7).sum().iloc[-1, 0] == 0.0

print(pd.__version__)
test_rolling_sum(np.float32)
test_rolling_sum(np.float64)

Problem description

The sum of a window of float32 zeros is zero, but the sum of a window of float64 zeros is a tiny, positive number. This is concerning, because ratio calculations like growth rates can "blow up" with tiny numbers.

Expected Output

0.23.4

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Linux
OS-release: 3.13.0-103-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.23.4
pytest: 3.9.1
pip: 18.1
setuptools: 39.1.0
Cython: None
numpy: 1.15.3
scipy: 1.1.0
pyarrow: 0.11.0
xarray: 0.10.9
IPython: 7.0.1
sphinx: None
patsy: 0.5.1
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.8
feather: None
matplotlib: 3.0.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.3
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: 2.7.5 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@chris-b1
Copy link
Contributor

Thanks for the report - this is the same issue as #13254 - would definitely take a PR to fix!

@chris-b1 chris-b1 added Bug Duplicate Report Duplicate issue or pull request Numeric Operations Arithmetic, Comparison, and Logical operations Window rolling, ewma, expanding labels Dec 10, 2018
@chris-b1 chris-b1 added this to the No action milestone Dec 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request Numeric Operations Arithmetic, Comparison, and Logical operations Window rolling, ewma, expanding
Projects
None yet
Development

No branches or pull requests

2 participants