Kesav Kolla
08/27/2025, 11:26 AMColin Ho
08/27/2025, 1:34 PMKesav Kolla
08/27/2025, 4:46 PMMalcolm Greaves
08/27/2025, 9:06 PMcrate::my_crate::my_rust_udf. For simplicity, I'll assume it's input is of a type called I and output is a type called O.
(2) The pyO3 code looks roughly like:
use pyo3::prelude::*;
<https://pyo3.rs/v0.25.1/module>
crate::my_crate::my_rust_udf;
#[pyfunction]
fn py_rust_udf_scalar(x: I) -> O {
my_rust_udf(x)
}
#[pymodule]
fn py_rust_module(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(py_rust_udf_scalar, m)?)
}
(3) Use manturin in your pyproject.toml and build this code:
https://github.com/PyO3/maturin
(4) Make your daft UDF:
import daft
from py_rust_module import py_rust_udf_scalar
@daft.udf(
// you will have to figure out how to go from the python type to something daft understands
// if it's simple, like float, then this is just daft.DataType.float64()
// if it's complex, like an object, you'll want to define an appropriate struct or list type
return_dtype=...
)
def my_udf(xs: daft.Series):
return [py_rust_udf_scalar(x) for x in xs]
// use it!
df: daft.DataFrame = ...
df = df.with_column("new_col_name", my_udf(daft.col("input_col_name")))Cory Grinstead
08/27/2025, 10:18 PM#[pyfunction]
fn py_rust_udf_scalar(x: I, py:Python) -> O {
py.detach(|| move {my_rust_udf(x)})
}Cory Grinstead
08/28/2025, 3:12 AM@daft.func instead of the legacy @daft.udfKesav Kolla
08/28/2025, 9:47 AMAmir Shukayev
08/29/2025, 9:16 PM