polars_python/expr/
meta.rs

1use polars::prelude::Schema;
2use pyo3::prelude::*;
3
4use crate::PyExpr;
5use crate::error::PyPolarsErr;
6use crate::expr::ToPyExprs;
7use crate::prelude::Wrap;
8
9#[pymethods]
10impl 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 _meta_selector_add(&self, other: PyExpr) -> PyResult<PyExpr> {
74        let out = self
75            .inner
76            .clone()
77            .meta()
78            ._selector_add(other.inner)
79            .map_err(PyPolarsErr::from)?;
80        Ok(out.into())
81    }
82
83    fn _meta_selector_and(&self, other: PyExpr) -> PyResult<PyExpr> {
84        let out = self
85            .inner
86            .clone()
87            .meta()
88            ._selector_and(other.inner)
89            .map_err(PyPolarsErr::from)?;
90        Ok(out.into())
91    }
92
93    fn _meta_selector_sub(&self, other: PyExpr) -> PyResult<PyExpr> {
94        let out = self
95            .inner
96            .clone()
97            .meta()
98            ._selector_sub(other.inner)
99            .map_err(PyPolarsErr::from)?;
100        Ok(out.into())
101    }
102
103    fn _meta_selector_xor(&self, other: PyExpr) -> PyResult<PyExpr> {
104        let out = self
105            .inner
106            .clone()
107            .meta()
108            ._selector_xor(other.inner)
109            .map_err(PyPolarsErr::from)?;
110        Ok(out.into())
111    }
112
113    fn _meta_as_selector(&self) -> PyExpr {
114        self.inner.clone().meta()._into_selector().into()
115    }
116
117    fn compute_tree_format(
118        &self,
119        display_as_dot: bool,
120        schema: Option<Wrap<Schema>>,
121    ) -> Result<String, PyErr> {
122        let e = self
123            .inner
124            .clone()
125            .meta()
126            .into_tree_formatter(display_as_dot, schema.as_ref().map(|s| &s.0))
127            .map_err(PyPolarsErr::from)?;
128        Ok(format!("{e}"))
129    }
130
131    fn meta_tree_format(&self, schema: Option<Wrap<Schema>>) -> PyResult<String> {
132        self.compute_tree_format(false, schema)
133    }
134
135    fn meta_show_graph(&self, schema: Option<Wrap<Schema>>) -> PyResult<String> {
136        self.compute_tree_format(true, schema)
137    }
138}