Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Copy attrs on pd.merge() #60357

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

timhoffm
Copy link
Contributor

This uses the same logic as pd.concat(): Copy attrs only if all input attrs are identical.

I've refactored the handling in finalize from special-casing based on th the method name (previously only "concat") to handling "other" parameters that have an input_objs attribute. This is a more scalable architecture compared to hard-coding method names in finalize.

Tests added for concat() and merge().

Closes #60351.

This uses the same logic as `pd.concat()`: Copy `attrs` only if all
input `attrs` are identical.

I've refactored the handling in __finalize__ from special-casing based on th the method name (previously only "concat") to handling "other" parameters
that have an `input_objs` attribute. This is a more scalable architecture compared to hard-coding method names in __finalize__.

Tests added for `concat()` and `merge()`.

Closes pandas-dev#60351.
Comment on lines +1110 to +1113
result = result.__finalize__(
types.SimpleNamespace(input_objs=[self.left, self.right]),
method=self._merge_type,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I don't really understand why __finalize__ is called twice on the result, once here with method=self._merge_type and once below with method="merge". That looks dubious. If the duplication is needed, we should add a comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Copy attrs on join (possibly depending on left, right, etc.)
1 participant