Skip to content
Open
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
10 changes: 9 additions & 1 deletion ibis/backends/tests/test_asof_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def test_keyed_asof_join(
@pytest.mark.parametrize(
("direction", "op"), [("backward", operator.ge), ("forward", operator.le)]
)
@pytest.mark.parametrize("right_column_key", [None, "on_right_time"])
@pytest.mark.notimpl(
["clickhouse"], raises=AssertionError, reason="`time` is truncated to seconds"
)
Expand Down Expand Up @@ -251,8 +252,15 @@ def test_keyed_asof_join_with_tolerance(
time_keyed_df2,
direction,
op,
right_column_key,
):
on = op(time_keyed_left["time"], time_keyed_right["time"])
left_key = right_key = "time"
if right_column_key:
right_key = right_column_key
time_keyed_right = time_keyed_right.rename({right_column_key: "time"})
assert left_key != right_key

on = op(time_keyed_left[left_key], time_keyed_right[right_key])
expr = time_keyed_left.asof_join(
time_keyed_right, on, "key", tolerance=ibis.interval(days=2)
)
Expand Down
6 changes: 3 additions & 3 deletions ibis/expr/types/joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ def asof_join(
# 2. filter the asof join result using the `tolerance` parameter and
# the `on` parameter
# 3. perform a left join between the original left table and the
# filtered asof join result using the `on` parameter but this
# time as an equality predicate
# filtered asof join result using the left operand of the `on` and the corresponding column on
# the filtered asof join
if isinstance(on, str):
# self is always a JoinChain so reference one of the join tables
left_on = self.op().values[on].to_expr()
Expand All @@ -323,7 +323,7 @@ def asof_join(
filtered = joined.filter(
left_on <= right_on + tolerance, left_on >= right_on - tolerance
)
right_on = right_on.op().replace({right.op(): filtered.op()}).to_expr()
(right_on,) = filtered.bind(left_on)

# without joining twice the table would not contain the rows from
# the left table that do not match any row from the right table
Expand Down