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: rolling().skew modifies original data column #39404

Closed
1 task
jwyndham opened this issue Jan 25, 2021 · 1 comment
Closed
1 task

BUG: rolling().skew modifies original data column #39404

jwyndham opened this issue Jan 25, 2021 · 1 comment
Labels
Bug Duplicate Report Duplicate issue or pull request Window rolling, ewma, expanding

Comments

@jwyndham
Copy link

jwyndham commented Jan 25, 2021

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

  • [x ] 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.


Code Sample, a copy-pastable example

df = pd.DataFrame(np.random.random(100)*10, columns=['A'])
           A
0   5.076681
1   6.959102
2   9.989156
..       ...
97  3.475425
98  3.280561
99  6.966864

Apply skew to create new column and df['A'] is now modified unexpectedly

df['skew'] = df['A'].rolling(10).skew()
           A      skew
0   0.076681       NaN
1   1.959102       NaN
2   4.989156       NaN
..       ...       ...
97 -1.524575 -0.482644
98 -1.719439 -0.114206
99  1.966864 -0.414480

Problem description

rolling().skew modifies original data column. This is an unexpected and problematic behaviour since it does not occur with other rolling window methods like mean(), std() and `'kurt'. A coder would reasonably expect that these methods can be applied in the same way, therefore it is likely to cause issues that are hard to debug.

It can be worked around by using using copy, but again, this is a deviation from the usage of other similar methods: df['A'].copy().rolling(10).skew()

Expected Output

           A      skew
0   5.076681       NaN
1   6.959102       NaN
2   9.989156       NaN
..       ...       ...
97  3.475425 -0.482644
98  3.280561 -0.114206
99  6.966864 -0.414480

           A
0   5.076681
1   6.959102
2   9.989156
..       ...
97  3.475425
98  3.280561
99  6.966864

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 3e89b4c
python : 3.8.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_Australia.1252

pandas : 1.2.0
numpy : 1.19.5
pytz : 2020.5
dateutil : 2.8.1
pip : 20.3.3
setuptools : 40.8.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.3
numexpr : 2.7.2
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.0
sqlalchemy : None
tables : 3.6.1
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@jwyndham jwyndham added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 25, 2021
@asishm
Copy link
Contributor

asishm commented Jan 25, 2021

This is fixed in v1.2.1

Duplicate of #38908 and fixed by #38909

@jreback jreback added this to the No action milestone Jan 25, 2021
@jreback jreback added Duplicate Report Duplicate issue or pull request Window rolling, ewma, expanding and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 25, 2021
@jreback jreback closed this as completed Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request Window rolling, ewma, expanding
Projects
None yet
Development

No branches or pull requests

3 participants