diff --git a/crates/polars-plan/src/plans/conversion/join.rs b/crates/polars-plan/src/plans/conversion/join.rs index 9e33f2079d11..0cd7c1563719 100644 --- a/crates/polars-plan/src/plans/conversion/join.rs +++ b/crates/polars-plan/src/plans/conversion/join.rs @@ -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, diff --git a/py-polars/tests/unit/operations/test_inequality_join.py b/py-polars/tests/unit/operations/test_inequality_join.py index 428afa4f5c01..e639de2ac62e 100644 --- a/py-polars/tests/unit/operations/test_inequality_join.py +++ b/py-polars/tests/unit/operations/test_inequality_join.py @@ -5,6 +5,7 @@ import hypothesis.strategies as st import numpy as np +import pytest from hypothesis import given import polars as pl @@ -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"))