-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Unexpected behaviour of Series.rolling.corr
when using a Timedelta
based window.
#31286
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
Comments
cc @mroeschke |
The issue is mostly fixed now. The only thing left is the following: For the case described above, the result is near 1 not exactly one, because the std of the values is an irrational number, so std(a) * std(b) does not equal a.cov(b) in pandas/pandas/core/window/rolling.py Line 1904 in a0e0571
Is there a clever way around the numerical issues here? |
Just speculating: might |
Probably a little bit, but not in all cases. We have the same issues if var has to many decimals for floating point precision. We could change it nevertheless, because it may behave better in some cases. |
I think the leftover numerical precision issue with corr overlaps with #24019, so going to close in favor of that issue. |
Code Sample, a copy-pastable example if possible
Problem description
Both functions
f
andg
should return the same value for entries13 - 19
in the resulting series.Currently the result of
f
whenwindow = Timedelta(days=4)
is not the correlation between the values ofx
andy
which should be equal to1.0
for entries13 - 19
in the result.Computed values on a
DataFrame
are also affected, i.e.does also compute unexpected values for the crosscorrelation.
If
.corr
is replaced with.cov
inf
andg
both functions return identical results, so it is likely that it is caused by a difference in the normalisation in the correlation computation that is applied when usingf
and when usingg
.Expected Output
Output of
pd.show_versions()
pd.show_versions()
INSTALLED VERSIONS
commit : None
pandas : 0.25.3
numpy : 1.15.4
pytz : 2019.3
dateutil : 2.8.1
pip : 19.3.1
setuptools : 41.6.0.post20191030
Cython : 0.29.6
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.9.0
pandas_datareader: None
bs4 : 4.8.1
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 2.2.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.1.0
sqlalchemy : None
tables : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
The text was updated successfully, but these errors were encountered: