Skip to content

Commit

Permalink
refactor(api): remove by of asof_join() in favor of predicates (#…
Browse files Browse the repository at this point in the history
…8700)

Closes #7869.

BREAKING CHANGE: The `by` argument from `asof_join` is removed. Calls to `asof_join` that previously used `by` should pass those arguments to `predicates` instead.
  • Loading branch information
mfatihaktas authored Mar 20, 2024
1 parent 4ea4a1d commit 1a8eec8
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
6 changes: 4 additions & 2 deletions ibis/backends/dask/tests/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def test_asof_join(time_left, time_right, time_df1, time_df2):
def test_keyed_asof_join(
time_keyed_left, time_keyed_right, time_keyed_df1, time_keyed_df2
):
expr = time_keyed_left.asof_join(time_keyed_right, "time", by="key")[
expr = time_keyed_left.asof_join(time_keyed_right, "time", predicates="key")[
time_keyed_left, time_keyed_right.other_value
]
result = expr.compile()
Expand All @@ -254,7 +254,9 @@ def test_asof_join_overlapping_non_predicate(
time_keyed_df1.assign(collide=time_keyed_df1["key"] + time_keyed_df1["value"])
time_keyed_df2.assign(collide=time_keyed_df2["key"] + time_keyed_df2["other_value"])

expr = time_keyed_left.asof_join(time_keyed_right, on="time", by=[("key", "key")])
expr = time_keyed_left.asof_join(
time_keyed_right, on="time", predicates=[("key", "key")]
)
result = expr.compile()
expected = dd.merge_asof(
time_keyed_df1, time_keyed_df2, on="time", by="key", suffixes=("", "_right")
Expand Down
4 changes: 2 additions & 2 deletions ibis/backends/pandas/tests/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def test_asof_join_predicate(time_left, time_right, time_df1, time_df2):
def test_keyed_asof_join(
time_keyed_left, time_keyed_right, time_keyed_df1, time_keyed_df2
):
expr = time_keyed_left.asof_join(time_keyed_right, "time", by="key")
expr = time_keyed_left.asof_join(time_keyed_right, "time", predicates="key")
expr = expr.select(time_keyed_left, time_keyed_right.other_value)
result = expr.execute()
expected = pd.merge_asof(time_keyed_df1, time_keyed_df2, on="time", by="key")
Expand All @@ -345,7 +345,7 @@ def test_keyed_asof_join_with_tolerance(
time_keyed_left, time_keyed_right, time_keyed_df1, time_keyed_df2
):
expr = time_keyed_left.asof_join(
time_keyed_right, "time", by="key", tolerance=2 * ibis.interval(days=1)
time_keyed_right, "time", predicates="key", tolerance=2 * ibis.interval(days=1)
)
result = expr.execute()
expected = pd.merge_asof(
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/tests/test_asof_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_keyed_asof_join_with_tolerance(
):
on = op(time_keyed_left["time"], time_keyed_right["time"])
expr = time_keyed_left.asof_join(
time_keyed_right, on=on, by="key", tolerance=ibis.interval(days=2)
time_keyed_right, on=on, predicates="key", tolerance=ibis.interval(days=2)
)

result = con.execute(expr)
Expand Down
3 changes: 1 addition & 2 deletions ibis/expr/types/joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,12 @@ def asof_join(
right: Table,
on,
predicates=(),
by=(),
tolerance=None,
*,
lname: str = "",
rname: str = "{name}_right",
):
predicates = util.promote_list(predicates) + util.promote_list(by)
predicates = util.promote_list(predicates)
if tolerance is not None:
# `tolerance` parameter is mimicking the pandas API, but we express
# it at the expression level by a sequence of operations:
Expand Down
7 changes: 1 addition & 6 deletions ibis/expr/types/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3043,7 +3043,6 @@ def asof_join(
right: Table,
on: str | ir.BooleanColumn,
predicates: str | ir.Column | Sequence[str | ir.Column] = (),
by: str | ir.Column | Sequence[str | ir.Column] = (),
tolerance: str | ir.IntervalScalar | None = None,
*,
lname: str = "",
Expand All @@ -3054,8 +3053,6 @@ def asof_join(
Similar to a left join except that the match is done on nearest key
rather than equal keys.
Optionally, match keys with `by` before joining with `predicates`.
Parameters
----------
left
Expand All @@ -3066,8 +3063,6 @@ def asof_join(
Closest match inequality condition
predicates
Additional join predicates
by
Additional equality join predicates
tolerance
Amount of time to look behind when joining
lname
Expand All @@ -3085,7 +3080,7 @@ def asof_join(
from ibis.expr.types.joins import Join

return Join(left.op()).asof_join(
right, on, predicates, by=by, tolerance=tolerance, lname=lname, rname=rname
right, on, predicates, tolerance=tolerance, lname=lname, rname=rname
)

def cross_join(
Expand Down
4 changes: 2 additions & 2 deletions ibis/tests/expr/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ def test_asof_join_with_by():
)
assert join_without_by.op() == expected

join_with_by = api.asof_join(left, right, "time", by="key")
join_with_predicates = api.asof_join(left, right, "time", predicates="key")
with join_tables(left, right) as (r1, r2):
expected = ops.JoinChain(
first=r1,
Expand All @@ -1000,7 +1000,7 @@ def test_asof_join_with_by():
"value2": r2.value2,
},
)
assert join_with_by.op() == expected
assert join_with_predicates.op() == expected


@pytest.mark.parametrize(
Expand Down

0 comments on commit 1a8eec8

Please sign in to comment.