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: Fix metadata propagation in df.corr and df.cov, GH28283 #48616

Merged
merged 4 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/source/whatsnew/v1.6.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ Styler
-
-

Metadata
^^^^^^^^
- Fixed metadata propagation in :meth:`DataFrame.corr` and :meth:`DataFrame.cov` (:issue:`28283`)
-

Other
^^^^^

Expand Down
6 changes: 4 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10355,7 +10355,8 @@ def corr(
f"'{method}' was supplied"
)

return self._constructor(correl, index=idx, columns=cols)
result = self._constructor(correl, index=idx, columns=cols)
return result.__finalize__(self, method="corr")

def cov(
self,
Expand Down Expand Up @@ -10490,7 +10491,8 @@ def cov(
else:
base_cov = libalgos.nancorr(mat, cov=True, minp=min_periods)

return self._constructor(base_cov, index=idx, columns=cols)
result = self._constructor(base_cov, index=idx, columns=cols)
return result.__finalize__(self, method="cov")

def corrwith(
self,
Expand Down
6 changes: 1 addition & 5 deletions pandas/tests/generic/test_finalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,10 @@
pytest.param(
(pd.DataFrame, frame_data, operator.methodcaller("round", 2)),
),
pytest.param(
(pd.DataFrame, frame_data, operator.methodcaller("corr")),
marks=not_implemented_mark,
yuanx749 marked this conversation as resolved.
Show resolved Hide resolved
),
(pd.DataFrame, frame_data, operator.methodcaller("corr")),
pytest.param(
(pd.DataFrame, frame_data, operator.methodcaller("cov")),
marks=[
not_implemented_mark,
pytest.mark.filterwarnings("ignore::RuntimeWarning"),
],
),
Expand Down