Skip to content

rolling_mean returns small negative value on Series with non-negative values #10319

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
ahu2012 opened this issue Jun 9, 2015 · 1 comment · Fixed by #36348
Closed

rolling_mean returns small negative value on Series with non-negative values #10319

ahu2012 opened this issue Jun 9, 2015 · 1 comment · Fixed by #36348
Labels
Bug Window rolling, ewma, expanding
Milestone

Comments

@ahu2012
Copy link

ahu2012 commented Jun 9, 2015

We came upon this issue today while trying to take a square root of a non-negative series.

A quick search came up with this old issue: #2527 issue was reproduced on 0.15 by tweaking the code from the previous report, which is below:

from pandas import date_range, Series
s = Series(index=date_range('1999-02-03','1999-04-05'))
s['1999-02-03'] = 0.00012456
s['1999-02-04'] = 0.0003
s['1999-04-04'] = -0.0
s['1999-04-05'] = -0.0
In [21]: s.rolling(1).mean()['1999-04-05']
Out[21]: -5.421010862427522e-20

which returns -5.4210108624275222e-20.

@jreback
Copy link
Contributor

jreback commented Jun 9, 2015

does seem odd, but the value is indistinguishable from 0. so this is probably a round effect somewhere in cython. I'll mark it, but would need someone to deep dive into the code

In [43]: np.allclose([pd.rolling_mean(s, 1)['1999-04-05']],[0.0],atol=1e-20)
Out[43]: False

In [45]: np.allclose([pd.rolling_mean(s, 1)['1999-04-05']],[0.0],atol=1e-19)
Out[45]: True

@jreback jreback added the Numeric Operations Arithmetic, Comparison, and Logical operations label Jun 9, 2015
@jbrockmendel jbrockmendel added the Window rolling, ewma, expanding label Oct 21, 2019
@mroeschke mroeschke added Bug and removed Numeric Operations Arithmetic, Comparison, and Logical operations labels May 8, 2020
@jreback jreback added this to the 1.2 milestone Sep 15, 2020
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.

4 participants