()
| 439 | |
| 440 | |
| 441 | def test_asof_join(): |
| 442 | left = pa.table({'key': [1, 2, 3], 'ts': [1, 1, 1], 'a': [4, 5, 6]}) |
| 443 | left_source = Declaration("table_source", options=TableSourceNodeOptions(left)) |
| 444 | right = pa.table({'key': [2, 3, 4], 'ts': [2, 5, 2], 'b': [4, 5, 6]}) |
| 445 | right_source = Declaration("table_source", options=TableSourceNodeOptions(right)) |
| 446 | |
| 447 | # asof join |
| 448 | join_opts = AsofJoinNodeOptions( |
| 449 | left_on="ts", left_by=["key"], |
| 450 | right_on="ts", right_by=["key"], |
| 451 | tolerance=1, |
| 452 | ) |
| 453 | joined = Declaration( |
| 454 | "asofjoin", options=join_opts, inputs=[left_source, right_source] |
| 455 | ) |
| 456 | result = joined.to_table() |
| 457 | expected = pa.table( |
| 458 | [[1, 2, 3], [1, 1, 1], [4, 5, 6], [None, 4, None]], |
| 459 | names=["key", "ts", "a", "b"]) |
| 460 | assert result == expected |
| 461 | |
| 462 | for by in [field("key"), ["key"], [field("key")]]: |
| 463 | for on in [field("ts"), "ts"]: |
| 464 | join_opts = AsofJoinNodeOptions( |
| 465 | left_on=on, left_by=by, |
| 466 | right_on=on, right_by=by, |
| 467 | tolerance=1, |
| 468 | ) |
| 469 | joined = Declaration( |
| 470 | "asofjoin", options=join_opts, inputs=[left_source, right_source]) |
| 471 | result = joined.to_table() |
| 472 | assert result == expected |
| 473 | |
| 474 | |
| 475 | @pytest.mark.dataset |
nothing calls this directly
no test coverage detected