Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-python/src/expr/meta.rs
7889 views
1
use polars::prelude::Schema;
2
use pyo3::prelude::*;
3
4
use crate::PyExpr;
5
use crate::error::PyPolarsErr;
6
use crate::expr::ToPyExprs;
7
use crate::prelude::Wrap;
8
9
#[pymethods]
10
impl PyExpr {
11
fn meta_eq(&self, other: Self) -> bool {
12
self.inner == other.inner
13
}
14
15
fn meta_pop(&self, schema: Option<Wrap<Schema>>) -> PyResult<Vec<Self>> {
16
let schema = schema.as_ref().map(|s| &s.0);
17
let exprs = self
18
.inner
19
.clone()
20
.meta()
21
.pop(schema)
22
.map_err(PyPolarsErr::from)?;
23
Ok(exprs.to_pyexprs())
24
}
25
26
fn meta_root_names(&self) -> Vec<String> {
27
self.inner
28
.clone()
29
.meta()
30
.root_names()
31
.iter()
32
.map(|name| name.to_string())
33
.collect()
34
}
35
36
fn meta_output_name(&self) -> PyResult<String> {
37
let name = self
38
.inner
39
.clone()
40
.meta()
41
.output_name()
42
.map_err(PyPolarsErr::from)?;
43
Ok(name.to_string())
44
}
45
46
fn meta_undo_aliases(&self) -> Self {
47
self.inner.clone().meta().undo_aliases().into()
48
}
49
50
fn meta_has_multiple_outputs(&self) -> bool {
51
self.inner.clone().meta().has_multiple_outputs()
52
}
53
54
fn meta_is_column(&self) -> bool {
55
self.inner.clone().meta().is_column()
56
}
57
58
fn meta_is_regex_projection(&self) -> bool {
59
self.inner.clone().meta().is_regex_projection()
60
}
61
62
fn meta_is_column_selection(&self, allow_aliasing: bool) -> bool {
63
self.inner
64
.clone()
65
.meta()
66
.is_column_selection(allow_aliasing)
67
}
68
69
fn meta_is_literal(&self, allow_aliasing: bool) -> bool {
70
self.inner.clone().meta().is_literal(allow_aliasing)
71
}
72
73
fn compute_tree_format(
74
&self,
75
display_as_dot: bool,
76
schema: Option<Wrap<Schema>>,
77
) -> Result<String, PyErr> {
78
let e = self
79
.inner
80
.clone()
81
.meta()
82
.into_tree_formatter(display_as_dot, schema.as_ref().map(|s| &s.0))
83
.map_err(PyPolarsErr::from)?;
84
Ok(format!("{e}"))
85
}
86
87
fn meta_tree_format(&self, schema: Option<Wrap<Schema>>) -> PyResult<String> {
88
self.compute_tree_format(false, schema)
89
}
90
91
fn meta_show_graph(&self, schema: Option<Wrap<Schema>>) -> PyResult<String> {
92
self.compute_tree_format(true, schema)
93
}
94
}
95
96