Skip to content

Commit

Permalink
reorganise
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Mar 6, 2024
1 parent 179b898 commit c60c5d3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 98 deletions.
4 changes: 2 additions & 2 deletions py-polars/polars/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def register_plugin(
Parameters
----------
plugin_location
Path to package where plugin is located. This should either be the
directory containing the plugin module, or a path to the dynamic library file.
Path to package where plugin is located. This should either be the dynamic
library file, or the directory containing it.
function_name
Rust function to load.
inputs
Expand Down
48 changes: 0 additions & 48 deletions py-polars/sample_plugin/sample_plugin/utils.py

This file was deleted.

48 changes: 0 additions & 48 deletions py-polars/src/functions/aggregation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::Arc;

use polars::lazy::dsl;
use pyo3::prelude::*;

Expand Down Expand Up @@ -48,49 +46,3 @@ pub fn mean_horizontal(exprs: Vec<PyExpr>) -> PyResult<PyExpr> {
let e = dsl::mean_horizontal(exprs).map_err(PyPolarsErr::from)?;
Ok(e.into())
}

#[cfg(feature = "ffi_plugin")]
#[pyfunction]
pub fn register_plugin(
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<PyExpr> {
use polars_plan::prelude::*;

let collect_groups = if is_elementwise {
ApplyOptions::ElementWise
} else {
ApplyOptions::GroupWise
};
let mut input = Vec::with_capacity(args.len());
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())
}
49 changes: 49 additions & 0 deletions py-polars/src/functions/misc.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,59 @@
use std::sync::Arc;

use pyo3::prelude::*;

use crate::conversion::Wrap;
use crate::prelude::DataType;
use crate::PyExpr;

#[pyfunction]
pub fn dtype_str_repr(dtype: Wrap<DataType>) -> PyResult<String> {
let dtype = dtype.0;
Ok(dtype.to_string())
}

#[cfg(feature = "ffi_plugin")]
#[pyfunction]
pub fn register_plugin(
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<PyExpr> {
use polars_plan::prelude::*;

let collect_groups = if is_elementwise {
ApplyOptions::ElementWise
} else {
ApplyOptions::GroupWise
};
let mut input = Vec::with_capacity(args.len());
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())
}

0 comments on commit c60c5d3

Please sign in to comment.