Skip to content

Conversation

rit4rosa
Copy link

@rit4rosa rit4rosa commented Jun 19, 2025

Add coalesce_keys option to DataFrame.join for preserving join keys

This adds a coalesce_keys keyword to DataFrame.join to allow preservation
of both join key columns (id and id_right), instead of automatically
coalescing them into a single column.

This is especially useful in full outer joins, where retaining information
about unmatched keys from both sides is important.

Example:
df1.join(df2, on=id, coalesce_keys=False)

This will result in both id and id_right columns being preserved, rather
than merged into a single id.

Includes:

  • Modifications to join internals (core/reshape/merge.py)
  • A dedicated test file (test_merge_coalesce.py) covering:
    • Preservation of join keys when coalesce_keys=False
    • Comparison with default behavior (coalesce_keys=True)
    • Full outer joins with asymmetric key presence

This adds a coalesce_keys keyword to DataFrame.join to allow
preservation of both join key columns (id and id_right),
instead of automatically coalescing them into a single column.

This is especially useful in full outer joins, where retaining
information about unmatched keys from both sides is important.

Example:
    df1.join(df2, on=id, coalesce_keys=False)

This will result in both id and id_right columns being preserved,
rather than merged into a single id.

Includes:
- Modifications to join internals (core/reshape/merge.py)
- A dedicated test file (test_merge_coalesce.py) covering:
    - Preservation of join keys when coalesce_keys=False
    - Comparison with default behavior (coalesce_keys=True)
    - Full outer joins with asymmetric key presence

Co-authored-by: Maria Pereira <[email protected]>
@simonjayhawkins
Copy link
Member

closes #61033

@simonjayhawkins simonjayhawkins added Enhancement Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Jun 25, 2025
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 Jul 26, 2025
@mroeschke
Copy link
Member

Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.

@mroeschke mroeschke closed this Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Reshaping Concat, Merge/Join, Stack/Unstack, Explode Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants