Skip to content

Commit

Permalink
fix: Fix right join schema (#17833)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jul 24, 2024
1 parent 4c19115 commit 987d9b2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/polars-plan/src/plans/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ pub(crate) fn det_join_schema(
let mut arena = Arena::with_capacity(8);
let mut join_on_left: PlHashSet<_> = PlHashSet::with_capacity(left_on.len());
for e in left_on {
let field = e.to_field_amortized(schema_right, Context::Default, &mut arena)?;
let field = e.to_field_amortized(schema_left, Context::Default, &mut arena)?;
join_on_left.insert(field.name);
}

Expand Down
24 changes: 24 additions & 0 deletions py-polars/tests/unit/operations/test_join_right.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,27 @@ def test_right_join_schemas_multikey() -> None:
assert b.join(a, on=["a", "b"], how="right", coalesce=True).to_dict(
as_series=False
) == {"c": [1, None, 3], "a": [1, 2, 3], "b": [1, 2, 3], "c_right": [1, 2, 3]}


def test_join_right_different_key() -> None:
df = pl.DataFrame(
{
"foo": [1, 2, 3],
"bar": [6.0, 7.0, 8.0],
"ham1": ["a", "b", "c"],
}
)
other_df = pl.DataFrame(
{
"apple": ["x", "y", "z"],
"ham2": ["a", "b", "d"],
}
)
assert df.join(other_df, left_on="ham1", right_on="ham2", how="right").to_dict(
as_series=False
) == {
"foo": [1, 2, None],
"bar": [6.0, 7.0, None],
"apple": ["x", "y", "z"],
"ham2": ["a", "b", "d"],
}

0 comments on commit 987d9b2

Please sign in to comment.