From 263225cdd1ed602c30761ed2d2ce12ed3ababc98 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Fri, 15 Mar 2024 14:51:42 +0100 Subject: [PATCH] Redirect to new function --- py-polars/polars/expr/expr.py | 41 +++++++++++++----------------- py-polars/src/expr/general.rs | 48 ----------------------------------- 2 files changed, 17 insertions(+), 72 deletions(-) diff --git a/py-polars/polars/expr/expr.py b/py-polars/polars/expr/expr.py index 7cf33cc9b115..14a00f81eafa 100644 --- a/py-polars/polars/expr/expr.py +++ b/py-polars/polars/expr/expr.py @@ -9635,7 +9635,7 @@ def register_plugin( cast_to_supertypes: bool = False, pass_name_to_apply: bool = False, changes_length: bool = False, - ) -> Self: + ) -> Expr: """ Register a plugin function. @@ -9683,31 +9683,24 @@ def register_plugin( changes_length For example a `unique` or a `slice` """ + from polars.plugins import register_plugin_function + if args is None: - args = [] - else: - args = [parse_as_expression(a) for a in args] - if kwargs is None: - serialized_kwargs = b"" + args = [self] else: - import pickle + args = [self, *list(args)] - # Choose the highest protocol supported by https://docs.rs/serde-pickle/latest/serde_pickle/ - serialized_kwargs = pickle.dumps(kwargs, protocol=5) - - return self._from_pyexpr( - self._pyexpr.register_plugin( - lib, - symbol, - args, - serialized_kwargs, - is_elementwise, - input_wildcard_expansion, - returns_scalar, - cast_to_supertypes, - pass_name_to_apply, - changes_length, - ) + return register_plugin_function( + plugin_path=lib, + function_name=symbol, + args=args, + kwargs=kwargs, + is_elementwise=is_elementwise, + changes_length=changes_length, + returns_scalar=returns_scalar, + cast_to_supertype=cast_to_supertypes, + input_wildcard_expansion=input_wildcard_expansion, + pass_name_to_apply=pass_name_to_apply, ) @deprecate_renamed_function("register_plugin", version="0.19.12") @@ -9722,7 +9715,7 @@ def _register_plugin( input_wildcard_expansion: bool = False, auto_explode: bool = False, cast_to_supertypes: bool = False, - ) -> Self: + ) -> Expr: return self.register_plugin( lib=lib, symbol=symbol, diff --git a/py-polars/src/expr/general.rs b/py-polars/src/expr/general.rs index 67d156e9e1c7..269236b7b2d4 100644 --- a/py-polars/src/expr/general.rs +++ b/py-polars/src/expr/general.rs @@ -863,54 +863,6 @@ impl PyExpr { .into() } - #[cfg(feature = "ffi_plugin")] - fn register_plugin( - &self, - lib: &str, - symbol: &str, - args: Vec, - kwargs: Vec, - is_elementwise: bool, - input_wildcard_expansion: bool, - returns_scalar: bool, - cast_to_supertypes: bool, - pass_name_to_apply: bool, - changes_length: bool, - ) -> PyResult { - use polars_plan::prelude::*; - let inner = self.inner.clone(); - - let collect_groups = if is_elementwise { - ApplyOptions::ElementWise - } else { - ApplyOptions::GroupWise - }; - let mut input = Vec::with_capacity(args.len() + 1); - input.push(inner); - for a in args { - input.push(a.inner) - } - - Ok(Expr::Function { - input, - function: FunctionExpr::FfiPlugin { - lib: Arc::from(lib), - symbol: Arc::from(symbol), - kwargs: Arc::from(kwargs), - }, - options: FunctionOptions { - collect_groups, - input_wildcard_expansion, - returns_scalar, - cast_to_supertypes, - pass_name_to_apply, - changes_length, - ..Default::default() - }, - } - .into()) - } - #[cfg(feature = "hist")] #[pyo3(signature = (bins, bin_count, include_category, include_breakpoint))] fn hist(