Skip to content

Commit

Permalink
feat(api): support passing Deferreds as predicates to joins
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCrews committed Jan 22, 2025
1 parent dc23b9f commit 5718c7e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
17 changes: 17 additions & 0 deletions ibis/backends/tests/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,20 @@ def test_positional_join(backend, con):
result = con.execute(j)
expected = pd.DataFrame({"x": [1, 2, 3], "x_right": [3, 2, 1]})
backend.assert_frame_equal(result, expected)


@pytest.mark.parametrize(
"preds",
[
pytest.param(ibis._.x.upper(), id="single"),
pytest.param([ibis._.x.upper()], id="single-list"),
pytest.param([ibis._.x.upper(), ibis._.x.lower()], id="multiple"),
],
)
def test_join_deferred(backend: BackendTest, con, preds):
t1 = ibis.memtable({"x": ["a", "b", "c"]})
t2 = ibis.memtable({"x": ["A", "B", "Z"]})
j = t1.inner_join(t2, predicates=preds)
result = con.execute(j)
expected = pd.DataFrame({"x": ["a", "b"], "x_right": ["A", "B"]})
backend.assert_frame_equal(result, expected)
3 changes: 1 addition & 2 deletions ibis/expr/types/joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import ibis.expr.operations as ops
from ibis import util
from ibis.common.deferred import Deferred
from ibis.common.egraph import DisjointSet
from ibis.common.exceptions import (
ExpressionError,
Expand Down Expand Up @@ -168,7 +167,7 @@ def prepare_predicates(

left, right = chain.to_expr(), right.to_expr()
for pred in util.promote_list(predicates):
if isinstance(pred, (Value, Deferred, bool)):
if isinstance(pred, (Value, bool)):
for bound in bind(left, pred):
yield deref_both.dereference(bound.op())
else:
Expand Down

0 comments on commit 5718c7e

Please sign in to comment.