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: DataFrame.corr clips values when cov=True #61213

Closed
3 tasks done
j-hendricks opened this issue Apr 2, 2025 · 0 comments
Closed
3 tasks done

BUG: DataFrame.corr clips values when cov=True #61213

j-hendricks opened this issue Apr 2, 2025 · 0 comments
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@j-hendricks
Copy link
Contributor

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

In [50]: x = pd.DataFrame({"A": [1, 2, None, 4], "B": [2, 4, None, 9]})

In [51]: x.cov()
Out[51]:
     A    B
A  1.0  1.0
B  1.0  1.0

In [52]: x.dropna().cov()
Out[52]:
          A     B
A  2.333333   5.5
B  5.500000  13.0

Issue Description

Stemming from #61154. DataFrame.corr was clipped between -1 and 1 to handle numerical precision errors. However, this was done regardless of whether cov equals True or False, and should instead only be done when cov=False.

Expected Behavior

import pandas as pd

In [50]: x = pd.DataFrame({"A": [1, 2, None, 4], "B": [2, 4, None, 9]})

In [51]: x.cov()
Out[51]:
A B
A 1.0 1.0
B 1.0 1.0

In [52]: x.dropna().cov()
Out[52]:
A B
A 1.0 1.0
B 1.0 1.0

Installed Versions

commit : cdc9e95
python : 3.10.16
python-bits : 64
OS : Darwin
OS-release : 24.3.0
Version : Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:22 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6041
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 3.0.0.dev0+2006.gcdc9e952f1
numpy : 1.26.4
dateutil : 2.9.0.post0
pip : 25.0.1
Cython : 3.0.12
sphinx : 8.1.3
IPython : 8.34.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.13.3
blosc : None
bottleneck : 1.4.2
fastparquet : 2024.11.0
fsspec : 2025.3.0
html5lib : 1.1
hypothesis : 6.130.4
gcsfs : 2025.3.0
jinja2 : 3.1.6
lxml.etree : 5.3.1
matplotlib : 3.10.1
numba : 0.61.0
numexpr : 2.10.2
odfpy : None
openpyxl : 3.1.5
psycopg2 : 2.9.9
pymysql : 1.4.6
pyarrow : 19.0.1
pyreadstat : 1.2.8
pytest : 8.3.5
python-calamine : None
pytz : 2025.2
pyxlsb : 1.0.10
s3fs : 2025.3.0
scipy : 1.15.2
sqlalchemy : 2.0.40
tables : 3.10.1
tabulate : 0.9.0
xarray : 2024.9.0
xlrd : 2.0.1
xlsxwriter : 3.2.2
zstandard : 0.23.0
tzdata : 2025.2
qtpy : None
pyqt5 : None

@j-hendricks j-hendricks added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

1 participant