polars_python/expr/
meta.rs

1use pyo3::prelude::*;
2
3use crate::PyExpr;
4use crate::error::PyPolarsErr;
5use crate::expr::ToPyExprs;
6
7#[pymethods]
8impl PyExpr {
9    fn meta_eq(&self, other: Self) -> bool {
10        self.inner == other.inner
11    }
12
13    fn meta_pop(&self) -> PyResult<Vec<Self>> {
14        let exprs = self.inner.clone().meta().pop().map_err(PyPolarsErr::from)?;
15        Ok(exprs.to_pyexprs())
16    }
17
18    fn meta_root_names(&self) -> Vec<String> {
19        self.inner
20            .clone()
21            .meta()
22            .root_names()
23            .iter()
24            .map(|name| name.to_string())
25            .collect()
26    }
27
28    fn meta_output_name(&self) -> PyResult<String> {
29        let name = self
30            .inner
31            .clone()
32            .meta()
33            .output_name()
34            .map_err(PyPolarsErr::from)?;
35        Ok(name.to_string())
36    }
37
38    fn meta_undo_aliases(&self) -> Self {
39        self.inner.clone().meta().undo_aliases().into()
40    }
41
42    fn meta_has_multiple_outputs(&self) -> bool {
43        self.inner.clone().meta().has_multiple_outputs()
44    }
45
46    fn meta_is_column(&self) -> bool {
47        self.inner.clone().meta().is_column()
48    }
49
50    fn meta_is_regex_projection(&self) -> bool {
51        self.inner.clone().meta().is_regex_projection()
52    }
53
54    fn meta_is_column_selection(&self, allow_aliasing: bool) -> bool {
55        self.inner
56            .clone()
57            .meta()
58            .is_column_selection(allow_aliasing)
59    }
60
61    fn meta_is_literal(&self, allow_aliasing: bool) -> bool {
62        self.inner.clone().meta().is_literal(allow_aliasing)
63    }
64
65    fn _meta_selector_add(&self, other: PyExpr) -> PyResult<PyExpr> {
66        let out = self
67            .inner
68            .clone()
69            .meta()
70            ._selector_add(other.inner)
71            .map_err(PyPolarsErr::from)?;
72        Ok(out.into())
73    }
74
75    fn _meta_selector_and(&self, other: PyExpr) -> PyResult<PyExpr> {
76        let out = self
77            .inner
78            .clone()
79            .meta()
80            ._selector_and(other.inner)
81            .map_err(PyPolarsErr::from)?;
82        Ok(out.into())
83    }
84
85    fn _meta_selector_sub(&self, other: PyExpr) -> PyResult<PyExpr> {
86        let out = self
87            .inner
88            .clone()
89            .meta()
90            ._selector_sub(other.inner)
91            .map_err(PyPolarsErr::from)?;
92        Ok(out.into())
93    }
94
95    fn _meta_selector_xor(&self, other: PyExpr) -> PyResult<PyExpr> {
96        let out = self
97            .inner
98            .clone()
99            .meta()
100            ._selector_xor(other.inner)
101            .map_err(PyPolarsErr::from)?;
102        Ok(out.into())
103    }
104
105    fn _meta_as_selector(&self) -> PyExpr {
106        self.inner.clone().meta()._into_selector().into()
107    }
108
109    fn compute_tree_format(&self, display_as_dot: bool) -> Result<String, PyErr> {
110        let e = self
111            .inner
112            .clone()
113            .meta()
114            .into_tree_formatter(display_as_dot)
115            .map_err(PyPolarsErr::from)?;
116        Ok(format!("{e}"))
117    }
118
119    fn meta_tree_format(&self) -> PyResult<String> {
120        self.compute_tree_format(false)
121    }
122
123    fn meta_show_graph(&self) -> PyResult<String> {
124        self.compute_tree_format(true)
125    }
126}