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: roll_skew and roll_kurt compute different result when input same data with diffrent length #54380

Open
3 tasks done
cutebomb opened this issue Aug 3, 2023 · 5 comments
Open
3 tasks done
Labels
Bug Window rolling, ewma, expanding

Comments

@cutebomb
Copy link

cutebomb commented Aug 3, 2023

Pandas version checks

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

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

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
import numpy as np

a = np.random.random(20)*1000
a1 = a[:10]
a2 = a[:12]
df = pd.Series(a1)
df2 = pd.Series(a2)
r1 = df.rolling(8, min_periods=1).skew()
r2 = df2.rolling(8, min_periods=1).skew()
print(np.where(r1.values[:10] == r2.values[:10]))

r1 = df.rolling(8, min_periods=1).kurt()
r2 = df2.rolling(8, min_periods=1).kurt()
print(np.where(r1.values[:10] == r2.values[:10]))

Issue Description

rolling skew and kurt compute different result when input same data with diffrent length.
With the rolling window of exactly same data, I think it is wired to have different result right?
It is basically caused by minus mean value from the series, in source tree pandas/_libs/window/aggregations.pyx:621-624 and same code exist in roll_kurt too.

Expected Behavior

rolling skew and kurt result should be same.

Installed Versions

INSTALLED VERSIONS

commit : 0f43794
python : 3.10.7.final.0
python-bits : 64
OS : Linux
OS-release : 5.19.0-46-generic
Version : #47-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 16 13:30:11 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.0.3
numpy : 1.23.1
pytz : 2023.3
dateutil : 2.8.2
setuptools : 59.6.0
pip : 23.2.1
Cython : 0.29.34
pytest : 7.3.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.1.2
lxml.etree : 4.9.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.13.2
pandas_datareader: None
bs4 : 4.12.2
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2023.5.0
gcsfs : None
matplotlib : 3.7.1
numba : 0.57.0
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 12.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
snappy : None
sqlalchemy : 2.0.16
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

@cutebomb cutebomb added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 3, 2023
@cutebomb cutebomb changed the title BUG: rolling skew compute different result when input same data with diffrent length BUG: rolling skew and kurt compute different result when input same data with diffrent length Aug 3, 2023
@cutebomb cutebomb changed the title BUG: rolling skew and kurt compute different result when input same data with diffrent length BUG: roll_skew and roll_kurt compute different result when input same data with diffrent length Aug 3, 2023
@phofl
Copy link
Member

phofl commented Aug 6, 2023

Hi, thanks for your report. Are you sure that this is not caused by a loss of precision? Your values are quite large for these algorithms

@phofl phofl added Needs Info Clarification about behavior needed to assess issue Window rolling, ewma, expanding and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 6, 2023
@cutebomb
Copy link
Author

cutebomb commented Aug 10, 2023

I don't think it is caused by loss of precision, and value (-1000, 1000) is not very large value,is it?
The rolling algorithm nature should keep the old (hitorical) value stable with new values.
my temp fix to this problem is this commit: (by removing value minus mean code) cutebomb@c5391d4

Hi, thanks for your report. Are you sure that this is not caused by a loss of precision? Your values are quite large for these algorithms

@MattDXB
Copy link

MattDXB commented Feb 21, 2024

Hi, I am running into the same issue currently. Any ideas?

@cutebomb
Copy link
Author

Hi, I am running into the same issue currently. Any ideas?

check my patch for temp solution :)

@MattDXB
Copy link

MattDXB commented Mar 12, 2024

Yes, I saw it, thanks! The issue is that I'm in a company setting and I cannot recompile Cython code...

@mroeschke mroeschke added Window rolling, ewma, expanding and removed Window rolling, ewma, expanding Needs Info Clarification about behavior needed to assess issue labels Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Window rolling, ewma, expanding
Projects
None yet
Development

No branches or pull requests

4 participants