Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-plan/src/plans/apply.rs
6940 views
1
use std::fmt::{Debug, Formatter};
2
3
use polars_core::prelude::*;
4
5
pub trait DataFrameUdf: Send + Sync {
6
fn call_udf(&self, df: DataFrame) -> PolarsResult<DataFrame>;
7
}
8
9
impl<F> DataFrameUdf for F
10
where
11
F: Fn(DataFrame) -> PolarsResult<DataFrame> + Send + Sync,
12
{
13
fn call_udf(&self, df: DataFrame) -> PolarsResult<DataFrame> {
14
self(df)
15
}
16
}
17
18
pub trait DataFrameUdfMut: Send + Sync {
19
fn call_udf(&mut self, df: DataFrame) -> PolarsResult<DataFrame>;
20
}
21
22
impl<F> DataFrameUdfMut for F
23
where
24
F: FnMut(DataFrame) -> PolarsResult<DataFrame> + Send + Sync,
25
{
26
fn call_udf(&mut self, df: DataFrame) -> PolarsResult<DataFrame> {
27
self(df)
28
}
29
}
30
31
impl Debug for dyn DataFrameUdf {
32
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
33
write!(f, "dyn DataFrameUdf")
34
}
35
}
36
impl Debug for dyn DataFrameUdfMut {
37
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
38
write!(f, "dyn DataFrameUdfMut")
39
}
40
}
41
42
pub trait UdfSchema: Send + Sync {
43
fn get_schema(&self, input_schema: &Schema) -> PolarsResult<SchemaRef>;
44
}
45
46
impl<F> UdfSchema for F
47
where
48
F: Fn(&Schema) -> PolarsResult<SchemaRef> + Send + Sync,
49
{
50
fn get_schema(&self, input_schema: &Schema) -> PolarsResult<SchemaRef> {
51
self(input_schema)
52
}
53
}
54
55
impl Debug for dyn UdfSchema {
56
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
57
write!(f, "dyn UdfSchema")
58
}
59
}
60
61