diff --git a/doc/source/whatsnew/v1.6.0.rst b/doc/source/whatsnew/v1.6.0.rst index ccb73953884b4..e06349f73257b 100644 --- a/doc/source/whatsnew/v1.6.0.rst +++ b/doc/source/whatsnew/v1.6.0.rst @@ -256,6 +256,11 @@ Styler - - +Metadata +^^^^^^^^ +- Fixed metadata propagation in :meth:`DataFrame.corr` and :meth:`DataFrame.cov` (:issue:`28283`) +- + Other ^^^^^ diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 79e8b2ed806c8..145e49f57335f 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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, @@ -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, diff --git a/pandas/tests/generic/test_finalize.py b/pandas/tests/generic/test_finalize.py index af1a76a6263c7..3c40218ef9024 100644 --- a/pandas/tests/generic/test_finalize.py +++ b/pandas/tests/generic/test_finalize.py @@ -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"), ], ),