Skip to content

Change of rolling behavior in Pandas 1.0.0 vs 0.25.3 #31719

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
icexelloss opened this issue Feb 5, 2020 · 2 comments
Closed

Change of rolling behavior in Pandas 1.0.0 vs 0.25.3 #31719

icexelloss opened this issue Feb 5, 2020 · 2 comments

Comments

@icexelloss
Copy link
Contributor

Code Sample, a copy-pastable example if possible

df = pd.DataFrame({
        'a': np.arange(10, dtype=float),
        'b': [3.0, np.NaN] * 5,
        'key': list('ddeefffggh'),
    })

expected = df.sort_values(['key', 'a']).assign(
    rolled=lambda d: d.groupby('key')
    .b.rolling(3, min_periods=1)
    .apply(lambda x: x.mean(), raw=True)
    .reset_index(level=0, drop=True)
)

Problem description

1.0.0 result:

     a    b key  rolled                                                                                                                                                                                                                                                                                                                                                                    
0  0.0  3.0   d     3.0                                                                                                                                                                                                                                                                                                                                                                    
1  1.0  NaN   d     3.0                                                                                                                                                                                                                                                                                                                                                                    
2  2.0  3.0   e     3.0                                                                                                                                                                                                                                                                                                                                                                    
3  3.0  NaN   e     3.0                                                                                                                                                                                                                                                                                                                                                                    
4  4.0  3.0   f     3.0                                                                                                                                                                                                                                                                                                                                                                    
5  5.0  NaN   f     3.0                                                                                                                                                                                                                                                                                                                                                                    
6  6.0  3.0   f     3.0                                                                                                                                                                                                                                                                                                                                                                    
7  7.0  NaN   g     NaN                                                                                                                                                                                                                                                                                                                                                                    
8  8.0  3.0   g     3.0                                                                                                                                                                                                                                                                                                                                                                    
9  9.0  NaN   h     NaN

0.25.3 behavior:

     a    b key  rolled
0  0.0  3.0   d     3.0
1  1.0  NaN   d     NaN
2  2.0  3.0   e     3.0
3  3.0  NaN   e     NaN
4  4.0  3.0   f     3.0
5  5.0  NaN   f     NaN
6  6.0  3.0   f     NaN
7  7.0  NaN   g     NaN
8  8.0  3.0   g     NaN
9  9.0  NaN   h     NaN

Note: We receive a lot of issues on our GitHub tracker, so it is very possible that your issue has been posted before. Please check first before submitting so that we do not have to handle and close duplicates!

Note: Many problems can be resolved by simply upgrading pandas to the latest version. Before submitting, please check if that solution works for you. If possible, you may want to check if master addresses this issue, but that is not necessary.

For documentation-related issues, you can check the latest versions of the docs on master here:

https://pandas-docs.github.io/pandas-docs-travis/

If the issue has not been resolved there, go ahead and file it in the issue tracker.

Expected Output

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]

@jreback
Copy link
Contributor

jreback commented Feb 5, 2020

see #26996

@icexelloss
Copy link
Contributor Author

I see. Thanks! @jreback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants