polars_python/functions/
misc.rs

1use polars_plan::prelude::*;
2use pyo3::prelude::*;
3
4use crate::PyExpr;
5use crate::conversion::Wrap;
6use crate::expr::ToExprs;
7use crate::prelude::DataType;
8
9#[pyfunction]
10pub fn dtype_str_repr(dtype: Wrap<DataType>) -> PyResult<String> {
11    let dtype = dtype.0;
12    Ok(dtype.to_string())
13}
14
15#[cfg(feature = "ffi_plugin")]
16#[pyfunction]
17pub fn register_plugin_function(
18    plugin_path: &str,
19    function_name: &str,
20    args: Vec<PyExpr>,
21    kwargs: Vec<u8>,
22    is_elementwise: bool,
23    input_wildcard_expansion: bool,
24    returns_scalar: bool,
25    cast_to_supertype: bool,
26    pass_name_to_apply: bool,
27    changes_length: bool,
28) -> PyResult<PyExpr> {
29    let cast_to_supertypes = if cast_to_supertype {
30        Some(CastingRules::cast_to_supertypes())
31    } else {
32        None
33    };
34
35    let mut flags = FunctionFlags::default();
36    if is_elementwise {
37        flags.set_elementwise();
38    }
39    flags.set(FunctionFlags::LENGTH_PRESERVING, !changes_length);
40    flags.set(FunctionFlags::PASS_NAME_TO_APPLY, pass_name_to_apply);
41    flags.set(FunctionFlags::RETURNS_SCALAR, returns_scalar);
42    flags.set(
43        FunctionFlags::INPUT_WILDCARD_EXPANSION,
44        input_wildcard_expansion,
45    );
46
47    let options = FunctionOptions {
48        cast_options: cast_to_supertypes,
49        flags,
50        ..Default::default()
51    };
52
53    Ok(Expr::Function {
54        input: args.to_exprs(),
55        function: FunctionExpr::FfiPlugin {
56            flags: options,
57            lib: plugin_path.into(),
58            symbol: function_name.into(),
59            kwargs: kwargs.into(),
60        },
61    }
62    .into())
63}
64
65#[pyfunction]
66pub fn __register_startup_deps() {
67    #[cfg(feature = "object")]
68    unsafe {
69        crate::on_startup::register_startup_deps(true)
70    }
71}