Skip to content

Commit

Permalink
chore: Don't raise on multiple same names in ie_join (#18658)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 10, 2024
1 parent fe04390 commit 760ab20
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
21 changes: 14 additions & 7 deletions crates/polars-plan/src/plans/conversion/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,20 @@ pub fn resolve_join(
let left_on = to_expr_irs_ignore_alias(left_on, ctxt.expr_arena)?;
let right_on = to_expr_irs_ignore_alias(right_on, ctxt.expr_arena)?;
let mut joined_on = PlHashSet::new();
for (l, r) in left_on.iter().zip(right_on.iter()) {
polars_ensure!(
joined_on.insert((l.output_name(), r.output_name())),
InvalidOperation: "joining with repeated key names; already joined on {} and {}",
l.output_name(),
r.output_name()
)

#[cfg(feature = "iejoin")]
let check = !matches!(options.args.how, JoinType::IEJoin(_));
#[cfg(not(feature = "iejoin"))]
let check = true;
if check {
for (l, r) in left_on.iter().zip(right_on.iter()) {
polars_ensure!(
joined_on.insert((l.output_name(), r.output_name())),
InvalidOperation: "joining with repeated key names; already joined on {} and {}",
l.output_name(),
r.output_name()
)
}
}
drop(joined_on);

Expand Down
16 changes: 16 additions & 0 deletions py-polars/tests/unit/operations/test_inequality_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,19 @@ def test_raise_invalid_input_join_where() -> None:
df = pl.DataFrame({"id": [1, 2]})
with pytest.raises(pl.exceptions.InvalidOperationError):
df.join_where(df)


def test_ie_join_use_keys_multiple() -> None:
a = pl.LazyFrame({"a": [1, 2, 3], "x": [7, 2, 1]})
b = pl.LazyFrame({"b": [2, 2, 2], "x": [7, 1, 3]})

assert a.join_where(
b,
pl.col.a >= pl.col.b,
pl.col.a <= pl.col.b,
).collect().sort("x_right").to_dict(as_series=False) == {
"a": [2, 2, 2],
"x": [2, 2, 2],
"b": [2, 2, 2],
"x_right": [1, 3, 7],
}

0 comments on commit 760ab20

Please sign in to comment.