Skip to content
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

rolling_* with min_periods=0 #365

Closed
dieterv77 opened this issue Nov 15, 2011 · 2 comments

Comments

@dieterv77
Copy link
Contributor

commented Nov 15, 2011

I ran into a minor gotcha with the rolling_* methods, below is some ipython output to illustrate.
I set min_periods to 0, which in retrospect i realize is not a reasonable value, but i would either
expect the same behavior as min_periods=1 or maybe an error. For rolling_max, the issue is
with line 421 in moments.pyx:
"for i from minp - 1 <= i < N:"
so if minp==0 then the first value of i = -1, which will wreak all kinds of havoc.

In [10]: df
Out[10]:
0
0 7
1 9
2 8
3 20

In [11]: pandas.rolling_max(df,window=df.shape[0],min_periods=0)
Out[11]:
0
0 20
1 20
2 20
3 20

In [12]: pandas.rolling_max(df,window=df.shape[0],min_periods=1)
Out[12]:
0
0 7
1 9
2 9
3 20

@dieterv77

This comment has been minimized.

Copy link
Contributor Author

commented Nov 15, 2011

Here's a potential "fix":
dieterv77@4fa799d

@wesm

This comment has been minimized.

Copy link
Member

commented Nov 16, 2011

thanks for reporting this-- i did a little cleanup and handled the minp=0 case in all the moment functions in the above commit

@wesm wesm closed this Nov 16, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.