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

Function test_asof_join

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

Source from the content-addressed store, hash-verified

427
428
429def test_asof_join():
430 left = pa.table({'key': [1, 2, 3], 'ts': [1, 1, 1], 'a': [4, 5, 6]})
431 left_source = Declaration("table_source", options=TableSourceNodeOptions(left))
432 right = pa.table({'key': [2, 3, 4], 'ts': [2, 5, 2], 'b': [4, 5, 6]})
433 right_source = Declaration("table_source", options=TableSourceNodeOptions(right))
434
435 # asof join
436 join_opts = AsofJoinNodeOptions(
437 left_on="ts", left_by=["key"],
438 right_on="ts", right_by=["key"],
439 tolerance=1,
440 )
441 joined = Declaration(
442 "asofjoin", options=join_opts, inputs=[left_source, right_source]
443 )
444 result = joined.to_table()
445 expected = pa.table(
446 [[1, 2, 3], [1, 1, 1], [4, 5, 6], [None, 4, None]],
447 names=["key", "ts", "a", "b"])
448 assert result == expected
449
450 for by in [field("key"), ["key"], [field("key")]]:
451 for on in [field("ts"), "ts"]:
452 join_opts = AsofJoinNodeOptions(
453 left_on=on, left_by=by,
454 right_on=on, right_by=by,
455 tolerance=1,
456 )
457 joined = Declaration(
458 "asofjoin", options=join_opts, inputs=[left_source, right_source])
459 result = joined.to_table()
460 assert result == expected
461
462
463@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