Skip to content

Commit 75fc447

Browse files
committed
Address review comment
1 parent eae8a02 commit 75fc447

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pandas/core/frame.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7969,8 +7969,13 @@ def _arith_method_with_reindex(self, right: DataFrame, op) -> DataFrame:
79697969
new_right = right if rcol_indexer is None else right.iloc[:, rcol_indexer]
79707970

79717971
# GH#60498 For MultiIndex column alignment
7972-
new_left.columns = cols
7973-
new_right.columns = cols
7972+
if isinstance(cols, MultiIndex):
7973+
# When overwriting column names, make a shallow copy so as to not modify
7974+
# the input DFs
7975+
new_left = new_left.copy(deep=False)
7976+
new_right = new_right.copy(deep=False)
7977+
new_left.columns = cols
7978+
new_right.columns = cols
79747979

79757980
result = op(new_left, new_right)
79767981

0 commit comments

Comments
 (0)