Skip to content

Commit 4464d00

Browse files
authored
fix(rust): Add Int128 path for join_asof (#21282)
1 parent 4eb4fb7 commit 4464d00

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

crates/polars-ops/src/frame/join/asof/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ pub trait AsofJoin: IntoDf {
297297
let ca = left_key.i32().unwrap();
298298
join_asof_numeric(ca, &right_key, strategy, tolerance, allow_eq)
299299
},
300+
#[cfg(feature = "dtype-i128")]
301+
DataType::Int128 => {
302+
let ca = left_key.i128().unwrap();
303+
join_asof_numeric(ca, &right_key, strategy, tolerance, allow_eq)
304+
},
300305
DataType::UInt64 => {
301306
let ca = left_key.u64().unwrap();
302307
join_asof_numeric(ca, &right_key, strategy, tolerance, allow_eq)

py-polars/tests/unit/operations/test_join_asof.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
import polars as pl
8+
from polars._typing import AsofJoinStrategy, PolarsIntegerType
89
from polars.exceptions import InvalidOperationError
910
from polars.testing import assert_frame_equal
1011

@@ -1287,3 +1288,30 @@ def test_join_asof_not_sorted() -> None:
12871288
df.join_asof(df, on="b", by="a")
12881289
with pytest.raises(InvalidOperationError, match="is not sorted"):
12891290
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

Comments
 (0)