Skip to content

Commit

Permalink
Fix for issue pandas-dev#28283: Ensure __finalize__ propagates metada…
Browse files Browse the repository at this point in the history
…ta correctly
  • Loading branch information
root committed May 16, 2024
1 parent 283a2dc commit 1e283bf
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5972,27 +5972,32 @@ def pipe(
# Attribute access

@final
def __finalize__(self, other, method: str | None = None, **kwargs) -> Self:
"""
Propagate metadata from other to self.

Parameters
----------
other : the object from which to get the attributes that we are going
to propagate
method : str, optional
A passed method name providing context on where ``__finalize__``
was called.
@final
def __finalize__(self, other, method: str | None = None, **kwargs) -> Self:
"""
Propagate metadata from other to self.
Parameters
----------
other : the object from which to get the attributes that we are going
to propagate
method : str, optional
A passed method name providing context on where ``__finalize__``
was called.
.. warning::
.. warning::
The value passed as `method` are not currently considered
stable across pandas releases.
"""
if isinstance(other, NDFrame):
if other.attrs:
self.attrs.update(other.attrs)
if hasattr(other, 'flags'):
self.flags = other.flags
return self

The value passed as `method` are not currently considered
stable across pandas releases.
"""
if isinstance(other, NDFrame):
if other.attrs:
# We want attrs propagation to have minimal performance
# impact if attrs are not used; i.e. attrs is an empty dict.
# One could make the deepcopy unconditionally, but a deepcopy
# of an empty dict is 50x more expensive than the empty check.
self.attrs = deepcopy(other.attrs)
Expand Down

0 comments on commit 1e283bf

Please sign in to comment.