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 3 commits 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.

@timhoffm timhoffm marked this pull request as draft November 19, 2024 06:39
@timhoffm timhoffm force-pushed the fix-merge-attrs branch 2 times, most recently from 1e8c04b to 6697172 Compare November 19, 2024 14:24
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.

Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Dec 20, 2024
@timhoffm
Copy link
Contributor Author

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

I'm still interested in this, and IMHO it's ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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