MCPcopy Create free account
hub / github.com/apache/arrow / test_asof_join

Function test_asof_join

python/pyarrow/tests/test_acero.py:532–563  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

530
531
532def test_asof_join():
533 left = pa.table({'key': [1, 2, 3], 'ts': [1, 1, 1], 'a': [4, 5, 6]})
534 left_source = Declaration("table_source", options=TableSourceNodeOptions(left))
535 right = pa.table({'key': [2, 3, 4], 'ts': [2, 5, 2], 'b': [4, 5, 6]})
536 right_source = Declaration("table_source", options=TableSourceNodeOptions(right))
537
538 # asof join
539 join_opts = AsofJoinNodeOptions(
540 left_on="ts", left_by=["key"],
541 right_on="ts", right_by=["key"],
542 tolerance=1,
543 )
544 joined = Declaration(
545 "asofjoin", options=join_opts, inputs=[left_source, right_source]
546 )
547 result = joined.to_table()
548 expected = pa.table(
549 [[1, 2, 3], [1, 1, 1], [4, 5, 6], [None, 4, None]],
550 names=["key", "ts", "a", "b"])
551 assert result == expected
552
553 for by in [field("key"), ["key"], [field("key")]]:
554 for on in [field("ts"), "ts"]:
555 join_opts = AsofJoinNodeOptions(
556 left_on=on, left_by=by,
557 right_on=on, right_by=by,
558 tolerance=1,
559 )
560 joined = Declaration(
561 "asofjoin", options=join_opts, inputs=[left_source, right_source])
562 result = joined.to_table()
563 assert result == expected
564
565
566@pytest.mark.dataset

Callers

nothing calls this directly

Calls 4

DeclarationClass · 0.90
TableSourceNodeOptionsFunction · 0.90
fieldFunction · 0.90
to_tableMethod · 0.45

Tested by

no test coverage detected