Skip to content

Commit ec0ad1b

Browse files
TomAugspurgerJulianWgs
authored andcommitted
BUG: Don't copy DataFrame columns as metadata (pandas-dev#37205)
1 parent 24e1a1e commit ec0ad1b

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/source/whatsnew/v1.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ Other
523523

524524
- Bug in :meth:`DataFrame.replace` and :meth:`Series.replace` incorrectly raising ``AssertionError`` instead of ``ValueError`` when invalid parameter combinations are passed (:issue:`36045`)
525525
- Bug in :meth:`DataFrame.replace` and :meth:`Series.replace` with numeric values and string ``to_replace`` (:issue:`34789`)
526+
- Fixed bug in metadata propagation incorrectly copying DataFrame columns as metadata when the column name overlaps with the metadata name (:issue:`37037`)
526527
- Fixed metadata propagation in the :class:`Series.dt` and :class:`Series.str` accessors (:issue:`28283`)
527528
- Bug in :meth:`Index.union` behaving differently depending on whether operand is a :class:`Index` or other list-like (:issue:`36384`)
528529
- Passing an array with 2 or more dimensions to the :class:`Series` constructor now raises the more specific ``ValueError``, from a bare ``Exception`` previously (:issue:`35744`)

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5364,7 +5364,7 @@ def __finalize__(
53645364

53655365
self.flags.allows_duplicate_labels = other.flags.allows_duplicate_labels
53665366
# For subclasses using _metadata.
5367-
for name in self._metadata:
5367+
for name in set(self._metadata) & set(other._metadata):
53685368
assert isinstance(name, str)
53695369
object.__setattr__(self, name, getattr(other, name, None))
53705370

pandas/tests/generic/test_finalize.py

+8
Original file line numberDiff line numberDiff line change
@@ -786,3 +786,11 @@ def test_groupby_finalize_not_implemented(obj, method):
786786
obj.attrs = {"a": 1}
787787
result = method(obj.groupby([0, 0]))
788788
assert result.attrs == {"a": 1}
789+
790+
791+
def test_finalize_frame_series_name():
792+
# https://github.com/pandas-dev/pandas/pull/37186/files#r506978889
793+
# ensure we don't copy the column `name` to the Series.
794+
df = pd.DataFrame({"name": [1, 2]})
795+
result = pd.Series([1, 2]).__finalize__(df)
796+
assert result.name is None

0 commit comments

Comments
 (0)