Skip to content

Commit

Permalink
Redirect to new function
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Mar 15, 2024
1 parent 0ea7c74 commit 263225c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 72 deletions.
41 changes: 17 additions & 24 deletions py-polars/polars/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand All @@ -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,
Expand Down
48 changes: 0 additions & 48 deletions py-polars/src/expr/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,54 +863,6 @@ impl PyExpr {
.into()
}

#[cfg(feature = "ffi_plugin")]
fn register_plugin(
&self,
lib: &str,
symbol: &str,
args: Vec<PyExpr>,
kwargs: Vec<u8>,
is_elementwise: bool,
input_wildcard_expansion: bool,
returns_scalar: bool,
cast_to_supertypes: bool,
pass_name_to_apply: bool,
changes_length: bool,
) -> PyResult<Self> {
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(
Expand Down

0 comments on commit 263225c

Please sign in to comment.