-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Numerical errors in rolling std (0.23.4) #27593
Comments
I encountered this on pandas 0.23.4, have not yet checked newer versions. Here's a case:
|
Updated |
@DieterDePaepe , the default for If you pass
Instead of all errors. All the windows here have exactly 0 variance so pandas does fumble that a little, but the window mean in these cases is still 9 orders of magnitude larger than pandas' error. Those differences are easy to explain. Pandas calculates a true rolling variance, whereas numpy calculates the variance for each window separately, in your code. As a result, %timeit np.sqrt(pd._libs.window.roll_var(STD_VAR_STABILITY_DATA,24,24, None, 'both', ddof=1)[23:])
%timeit np.std(sliding_window_view(STD_VAR_STABILITY_DATA, [24]), axis=1, ddof=1)
a=np.sqrt(pd._libs.window.roll_var(STD_VAR_STABILITY_DATA,24,24, None, 'both', ddof=1)[23:])
b=np.std(sliding_window_view(STD_VAR_STABILITY_DATA, [24]), axis=1, ddof=1)
np.allclose(a,b,atol=5e-6)
True Update |
Please consider updating your numpy/numpy#7753 (comment) there, since it's generally misleading. |
Apologies for the mixup of the Running on pandas 0.23.4, I do receive more differences between pandas and numpy, though indeed all absolute errors are below 5e-6. I was able to get an error up to 3e-6 though (see below). In my original use case, which caused me to investigate the rounding issues, I was mainly concerned with the relative error Example:
For the last window:
But I do agree Pandas faster approach will be useful in many other cases, I'll update my comment in the Numpy issue as requested. |
see the original change here: #6817 some amount of errors is expected |
@DieterDePaepe I saw your numpy/numpy#7753 (comment), can you provide more information and perhaps a reproducer? What pandas version? Your comment is from Jan 2019 and #18481 was merged in Late Nov 2018, does the issue still exist for you?
xref #9420 , #18430, #27202, #9420
The text was updated successfully, but these errors were encountered: