Skip to content

Commit aa0fa52

Browse files
yuanx749phofl
authored andcommitted
BUG: Fix metadata propagation in df.corr and df.cov, GH28283 (pandas-dev#48616)
* Add finalize to df.corr and df.cov * Clean
1 parent dce4c73 commit aa0fa52

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

doc/source/whatsnew/v1.6.0.rst

+5
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ Styler
258258
-
259259
-
260260

261+
Metadata
262+
^^^^^^^^
263+
- Fixed metadata propagation in :meth:`DataFrame.corr` and :meth:`DataFrame.cov` (:issue:`28283`)
264+
-
265+
261266
Other
262267
^^^^^
263268

pandas/core/frame.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -10356,7 +10356,8 @@ def corr(
1035610356
f"'{method}' was supplied"
1035710357
)
1035810358

10359-
return self._constructor(correl, index=idx, columns=cols)
10359+
result = self._constructor(correl, index=idx, columns=cols)
10360+
return result.__finalize__(self, method="corr")
1036010361

1036110362
def cov(
1036210363
self,
@@ -10491,7 +10492,8 @@ def cov(
1049110492
else:
1049210493
base_cov = libalgos.nancorr(mat, cov=True, minp=min_periods)
1049310494

10494-
return self._constructor(base_cov, index=idx, columns=cols)
10495+
result = self._constructor(base_cov, index=idx, columns=cols)
10496+
return result.__finalize__(self, method="cov")
1049510497

1049610498
def corrwith(
1049710499
self,

pandas/tests/generic/test_finalize.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,10 @@
192192
pytest.param(
193193
(pd.DataFrame, frame_data, operator.methodcaller("round", 2)),
194194
),
195-
pytest.param(
196-
(pd.DataFrame, frame_data, operator.methodcaller("corr")),
197-
marks=not_implemented_mark,
198-
),
195+
(pd.DataFrame, frame_data, operator.methodcaller("corr")),
199196
pytest.param(
200197
(pd.DataFrame, frame_data, operator.methodcaller("cov")),
201198
marks=[
202-
not_implemented_mark,
203199
pytest.mark.filterwarnings("ignore::RuntimeWarning"),
204200
],
205201
),

0 commit comments

Comments
 (0)