Skip to content

Commit

Permalink
refactor: Raise on suffixed predicate in join_where (#18607)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Sep 8, 2024
1 parent 98788b2 commit 04b9e82
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/polars-plan/src/plans/conversion/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ fn resolve_join_where(
let original_right = right;

for name in aexpr_to_leaf_names(right, ctxt.expr_arena) {
polars_ensure!(schema_right.contains(name.as_str()), ColumnNotFound: "could not find column {name} in the right table during join operation");
if schema_left.contains(name.as_str()) {
let new_name = _join_suffix_name(name.as_str(), suffix.as_str());
polars_ensure!(schema_right.contains(name.as_str()), ColumnNotFound: "could not find column {name} in the right table during join operation");

right = rename_matching_aexpr_leaf_names(
right,
Expand Down
9 changes: 7 additions & 2 deletions py-polars/tests/unit/operations/test_inequality_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import hypothesis.strategies as st
import numpy as np
import pytest
from hypothesis import given

import polars as pl
Expand Down Expand Up @@ -436,9 +437,13 @@ def test_ie_join_with_floats(
expr0 = _inequality_expression("dur", op1, "time")
expr1 = _inequality_expression("rev", op2, "cost")

print(east, west)
actual = east.join_where(west, expr0, expr1)
print(actual)

expected = east.join(west, how="cross").filter(expr0 & expr1)
assert_frame_equal(actual, expected, check_row_order=False, check_exact=True)


def test_raise_on_suffixed_predicate_18604() -> None:
df = pl.DataFrame({"id": [1, 2]})
with pytest.raises(pl.exceptions.ColumnNotFoundError):
df.join_where(df, pl.col("id") >= pl.col("id_right"))

0 comments on commit 04b9e82

Please sign in to comment.