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

chore: Don't raise on multiple same names in ie_join #18658

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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],
}