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

BUG: pandas 1.2.0 df.rolling().aggregate('skew') modified original data #38908

Closed
2 of 3 tasks
qinxuye opened this issue Jan 2, 2021 · 3 comments · Fixed by #38909
Closed
2 of 3 tasks

BUG: pandas 1.2.0 df.rolling().aggregate('skew') modified original data #38908

qinxuye opened this issue Jan 2, 2021 · 3 comments · Fixed by #38909
Labels
Regression Functionality that used to work in a prior pandas version Window rolling, ewma, expanding
Milestone

Comments

@qinxuye
Copy link

qinxuye commented Jan 2, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

# Your code here
In [1]: import pandas as pd

In [2]: pd.__version__
Out[2]: '1.2.0'

In [3]: import numpy as np

In [4]: df = pd.DataFrame({'a': [1., np.nan, 5.], 'b': [.1, .5, 1.0]})

In [5]: df
Out[5]: 
     a    b
0  1.0  0.1
1  NaN  0.5
2  5.0  1.0

In [6]: df.rolling(4).aggregate('skew')
Out[6]: 
    a   b
0 NaN NaN
1 NaN NaN
2 NaN NaN

In [7]: df
Out[7]: 
     a    b
0 -2.0 -0.9
1  NaN -0.5
2  2.0  0.0

Problem description

[this should explain why the current behaviour is a problem and why the expected output is a better solution]

For pandas 1.2.0, df.rolling().aggregate('skew') modified original data. And I verified that kurt has the same problem.

Expected Output

Original data should not be modified, the behavior works well in pandas 1.1.5.

In [1]: import pandas as pd                                                     

In [3]: import numpy as np                                                      

In [4]: df = pd.DataFrame({'a': [1., np.nan, 5.], 'b': [.1, .5, 1.0]})          

In [5]: pd.__version__                                                          
Out[5]: '1.1.5'

In [6]: df.rolling(4).aggregate('skew')                                         
Out[6]: 
    a   b
0 NaN NaN
1 NaN NaN
2 NaN NaN

In [7]: df                                                                      
Out[7]: 
     a    b
0  1.0  0.1
1  NaN  0.5
2  5.0  1.0

Output of pd.show_versions()

[paste the output of pd.show_versions() here leaving a blank line after the details tag]

In [8]: pd.show_versions()

INSTALLED VERSIONS

commit : 3e89b4c
python : 3.8.2.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : zh_CN.UTF-8
LOCALE : zh_CN.UTF-8

pandas : 1.2.0
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.1.3.post20200330
Cython : 0.29.16
pytest : 5.4.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.19.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : 2.7.2
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.15.1
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@qinxuye qinxuye added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 2, 2021
@mzeitlin11
Copy link
Member

Thanks for the report @qinxuye!

First bad commit 8dd2d95, PR (#37557)

@mzeitlin11 mzeitlin11 added Regression Functionality that used to work in a prior pandas version Window rolling, ewma, expanding and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 2, 2021
@mzeitlin11
Copy link
Member

Looks like just a copy needs to happen since input now gets modified:

if min_val - mean_val > -1e5:
mean_val = round(mean_val)
for i in range(0, N):
values[i] = values[i] - mean_val

@phofl
Copy link
Member

phofl commented Jan 2, 2021

kurt has the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Regression Functionality that used to work in a prior pandas version Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants