Skip to content

rolling_* with min_periods=0 #365

@dieterv77

Description

@dieterv77

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions