Skip to content

fix: Right join on multiple columns not coalescing left_on columns #21669

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

Merged
merged 1 commit into from
Mar 10, 2025

Conversation

lukemanley
Copy link
Contributor

fixes #20670
fixes #20671

Right join on multiple columns where left_on and right_on names do not match was failing to coalesce the left_on columns. The lazy schema was already producing the correct behavior.

import polars as pl

left = pl.LazyFrame({"a": [1, 2], "b": [1, 2]})
right = pl.LazyFrame({"c": [1, 2], "d": [1, 2]})

print(
    left.join(right, left_on=["a", "b"], right_on=["c", "d"], how="left").collect()
)

# shape: (2, 2)
# ┌─────┬─────┐
# │ a   ┆ b   │
# │ --- ┆ --- │
# │ i64 ┆ i64 │
# ╞═════╪═════╡
# │ 1   ┆ 1   │
# │ 2   ┆ 2   │
# └─────┴─────┘

print(
    left.join(right, left_on=["a", "b"], right_on=["c", "d"], how="right").collect()
)

# BEFORE:

# shape: (2, 4)
# ┌─────┬─────┬─────┬─────┐
# │ a   ┆ b   ┆ c   ┆ d   │
# │ --- ┆ --- ┆ --- ┆ --- │
# │ i64 ┆ i64 ┆ i64 ┆ i64 │
# ╞═════╪═════╪═════╪═════╡
# │ 1   ┆ 1   ┆ 1   ┆ 1   │
# │ 2   ┆ 2   ┆ 2   ┆ 2   │
# └─────┴─────┴─────┴─────┘

# AFTER:

# shape: (2, 2)
# ┌─────┬─────┐
# │ c   ┆ d   │
# │ --- ┆ --- │
# │ i64 ┆ i64 │
# ╞═════╪═════╡
# │ 1   ┆ 1   │
# │ 2   ┆ 2   │
# └─────┴─────┘

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Mar 10, 2025
Copy link

codecov bot commented Mar 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.47%. Comparing base (bcdc7da) to head (cddca79).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #21669      +/-   ##
==========================================
- Coverage   80.47%   80.47%   -0.01%     
==========================================
  Files        1605     1605              
  Lines      231842   231847       +5     
  Branches     2678     2678              
==========================================
+ Hits       186567   186569       +2     
- Misses      44647    44649       +2     
- Partials      628      629       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@ritchie46 ritchie46 left a comment

Choose a reason for hiding this comment

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

Nice!

@ritchie46 ritchie46 merged commit 9f840d2 into pola-rs:main Mar 10, 2025
27 checks passed
@lukemanley lukemanley deleted the right-join-multiple branch March 18, 2025 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lazy right join on multiple columns with subsequent drop fails Inconsistent behavior of right join on multiple columns
2 participants