>>> import ibis
>>> import pyarrow.compute as pc
>>> @ibis.udf.scalar.pyarrow
def add_one(x: int) -> int:
... return pc.add(x, 1)
... >>> expr = add_one(2)
>>> con = ibis.connect("duckdb://")
>>> con.execute(expr)
3
Scalar user-defined function APIs
scalar()
Scalar user-defined functions.
scalar
class itself is not a public API, its methods are.
Name | Description |
---|---|
pandas | Construct a vectorized scalar user-defined function that accepts pandas Series’ as inputs. |
pyarrow | Construct a vectorized scalar user-defined function that accepts PyArrow Arrays as input. |
python | Construct a non-vectorized scalar user-defined function that accepts Python scalar values as inputs. |
pandas(cls, fn=None, *args, name=None, schema=None, **kwargs)
Construct a vectorized scalar user-defined function that accepts pandas Series’ as inputs.
Name | Type | Description | Default |
---|---|---|---|
fn |
Callable | None | The The function to wrap. | None |
args |
Any | Configuration arguments for the UDF. | () |
name |
str | None | The name of the UDF in the backend if different from the function name. | None |
schema |
str | None | The schema in which to create the UDF. | None |
kwargs |
Any | Additional configuration arguments for the UDF. | {} |
pyarrow(cls, fn=None, *args, name=None, schema=None, **kwargs)
Construct a vectorized scalar user-defined function that accepts PyArrow Arrays as input.
Name | Type | Description | Default |
---|---|---|---|
fn |
Callable | None | The The function to wrap. | None |
args |
Any | Configuration arguments for the UDF. | () |
name |
str | None | The name of the UDF in the backend if different from the function name. | None |
schema |
str | None | The schema in which to create the UDF. | None |
kwargs |
Any | Additional configuration arguments for the UDF. | {} |
python(cls, fn=None, *args, name=None, schema=None, **kwargs)
Construct a non-vectorized scalar user-defined function that accepts Python scalar values as inputs.
python
UDFs are likely to be slow
Name | Type | Description | Default |
---|---|---|---|
fn |
Callable | None | The The function to wrap. | None |
args |
Any | Configuration arguments for the UDF. | () |
name |
str | None | The name of the UDF in the backend if different from the function name. | None |
schema |
str | None | The schema in which to create the UDF. | None |
kwargs |
Any | Additional configuration arguments for the UDF. | {} |