Skip to content

Commit

Permalink
BUG: Fix metadata propagation in df.corr and df.cov, GH28283 (pandas-…
Browse files Browse the repository at this point in the history
…dev#48616)

* Add finalize to df.corr and df.cov

* Clean
  • Loading branch information
yuanx749 authored and noatamir committed Nov 9, 2022
1 parent 5b08abb commit 41f424e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
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 @@ -258,6 +258,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 @@ -10356,7 +10356,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 @@ -10491,7 +10492,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,
),
(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

0 comments on commit 41f424e

Please sign in to comment.