-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Unexpected behavior for rolling moments when center=True and min_periods < window #8269
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
Comments
@seth-p I believe you added the additional |
@stahlous always |
Will try to take a look later today or tomorrow.
|
Ack. I think I might be misleading you by convoluting 0.14.1 with the dev version. However, the problem does stand for My apologies. I first noticed this with I'll re-state the issue this evening when I am able to get in front of my dev box again. |
I think this has been addressed in master (for 0.15.0) in #7934. Let me know if you still see a problem in master. |
I will try to check tonight/tomorrow if still need to fix rolling_apply. |
Sorry for the confusion. I did confirm that
Outputs:
Outputs:
I was able to hack together a patch for this in
The easier fix would be to have |
Ok, I will take a look and fix.
|
OK, I see what the problem is. When The current behavior is asymmetric in the sense that no Will try to come up with a different implementation that doesn't have this issue. |
I actually have a bit of a philosophical question about this. For simplicity, let's concentrate on the start rather than the edge of the array. Consider:
It's not obvious to me what we would want the first entry of the result to be. I can see two perfectly plausible possibilities: Currently (in master) the start of the array is treated as (a), but end of the array is treated as (b) (with Note that it only makes a difference (a) for functions that don't ignore I guess I'm slightly inclined to keep behavior (a) (and make it the behavior at the end as well) for backwards-compatibility reasons, but I'm not sure it's obvious... |
CCing @nbdanielson, since he raised #7925. |
I think option (a) is the more robust choice, but adding |
Yes, implementation-wise I am working on a slightly different implementation for |
I do see the dilemma here. My first thought is that (b) may be a more intuitive behavior, but I can't actually think of a filter where I would prefer this. So yes, I suppose (a) is a decent solution. This would be worth mentioning in the API as well |
I noticed while using rolling moment functions with
center=True
and withmin_periods
<window
that the values at the end of the series were showing up asNaN
when they should have be finite floating point values. The reason for this behavior is that_rolling_moment()
concats extraNaN
values to the end of the input series whencenter=True
to allow theroll_generic()
function to continue on past the end of the original series and compute the values that will "come within view" when the result is centered. However, adding thoseNaN
values into the window can bork the calculation and change a result that should be finite into aNaN
.This example illustrates the behavior:
I was able to mitigate this behavior, for one calculation at least, by modifying the cython function to essentially strip the trailing
NaN
values for the calculations made towards the end of the series. This requires passing in theoffset
calculated in_rolling_moment()
.Fixing this is going to touch a lot of functions that depend on
_rolling_moment()
. Before I go much further with this, I thought I'd raise the issue here and see if anyone else has insight or better ideas about how to fix this.The text was updated successfully, but these errors were encountered: