()
| 427 | |
| 428 | |
| 429 | def 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 |
nothing calls this directly
no test coverage detected