polars_python/functions/
misc.rs1use polars_plan::prelude::*;
2use pyo3::prelude::*;
3
4use crate::conversion::Wrap;
5use crate::expr::ToExprs;
6use crate::prelude::DataType;
7use crate::PyExpr;
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 collect_groups = if is_elementwise {
30 ApplyOptions::ElementWise
31 } else {
32 ApplyOptions::GroupWise
33 };
34
35 let cast_to_supertypes = if cast_to_supertype {
36 Some(CastingRules::cast_to_supertypes())
37 } else {
38 None
39 };
40
41 let mut flags = FunctionFlags::default();
42 flags.set(FunctionFlags::CHANGES_LENGTH, changes_length);
43 flags.set(FunctionFlags::PASS_NAME_TO_APPLY, pass_name_to_apply);
44 flags.set(FunctionFlags::RETURNS_SCALAR, returns_scalar);
45 flags.set(
46 FunctionFlags::INPUT_WILDCARD_EXPANSION,
47 input_wildcard_expansion,
48 );
49
50 Ok(Expr::Function {
51 input: args.to_exprs(),
52 function: FunctionExpr::FfiPlugin {
53 lib: plugin_path.into(),
54 symbol: function_name.into(),
55 kwargs: kwargs.into(),
56 },
57 options: FunctionOptions {
58 collect_groups,
59 cast_options: cast_to_supertypes,
60 flags,
61 ..Default::default()
62 },
63 }
64 .into())
65}
66
67#[pyfunction]
68pub fn __register_startup_deps() {
69 #[cfg(feature = "object")]
70 unsafe {
71 crate::on_startup::register_startup_deps(true)
72 }
73}