Description
-
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