|
5 | 5 | import pytest
|
6 | 6 |
|
7 | 7 | import polars as pl
|
| 8 | +from polars._typing import AsofJoinStrategy, PolarsIntegerType |
8 | 9 | from polars.exceptions import InvalidOperationError
|
9 | 10 | from polars.testing import assert_frame_equal
|
10 | 11 |
|
@@ -1287,3 +1288,30 @@ def test_join_asof_not_sorted() -> None:
|
1287 | 1288 | df.join_asof(df, on="b", by="a")
|
1288 | 1289 | with pytest.raises(InvalidOperationError, match="is not sorted"):
|
1289 | 1290 | df.join_asof(df, on="b")
|
| 1291 | + |
| 1292 | + |
| 1293 | +@pytest.mark.parametrize("left_dtype", [pl.Int64, pl.UInt64]) |
| 1294 | +@pytest.mark.parametrize("right_dtype", [pl.Int64, pl.UInt64]) |
| 1295 | +@pytest.mark.parametrize("strategy", ["backward", "forward", "nearest"]) |
| 1296 | +def test_join_asof_large_int_21276( |
| 1297 | + left_dtype: PolarsIntegerType, |
| 1298 | + right_dtype: PolarsIntegerType, |
| 1299 | + strategy: AsofJoinStrategy, |
| 1300 | +) -> None: |
| 1301 | + large_int64 = 1608129000134000123 # it only happen when "on" column is large |
| 1302 | + left = pl.DataFrame({"ts": pl.Series([large_int64 + 2], dtype=left_dtype)}) |
| 1303 | + right = pl.DataFrame( |
| 1304 | + { |
| 1305 | + "ts": pl.Series([large_int64 + 1, large_int64 + 3], dtype=right_dtype), |
| 1306 | + "value": [111, 333], |
| 1307 | + } |
| 1308 | + ) |
| 1309 | + result = left.join_asof(right, on="ts", strategy=strategy) |
| 1310 | + idx = 0 if strategy == "backward" else 1 |
| 1311 | + expected = pl.DataFrame( |
| 1312 | + { |
| 1313 | + "ts": left["ts"], |
| 1314 | + "value": right["value"].gather(idx), |
| 1315 | + } |
| 1316 | + ) |
| 1317 | + assert_frame_equal(result, expected) |
0 commit comments