polars_python/expr/
struct.rs1use pyo3::prelude::*;
2
3use crate::PyExpr;
4use crate::error::PyPolarsErr;
5use crate::expr::ToExprs;
6
7#[pymethods]
8impl PyExpr {
9 fn struct_field_by_index(&self, index: i64) -> Self {
10 self.inner.clone().struct_().field_by_index(index).into()
11 }
12
13 fn struct_field_by_name(&self, name: &str) -> Self {
14 self.inner.clone().struct_().field_by_name(name).into()
15 }
16
17 fn struct_multiple_fields(&self, names: Vec<String>) -> Self {
18 self.inner.clone().struct_().field_by_names(&names).into()
19 }
20
21 fn struct_rename_fields(&self, names: Vec<String>) -> Self {
22 self.inner.clone().struct_().rename_fields(names).into()
23 }
24
25 #[cfg(feature = "json")]
26 fn struct_json_encode(&self) -> Self {
27 self.inner.clone().struct_().json_encode().into()
28 }
29
30 fn struct_with_fields(&self, fields: Vec<PyExpr>) -> PyResult<Self> {
31 let fields = fields.to_exprs();
32 let e = self
33 .inner
34 .clone()
35 .struct_()
36 .with_fields(fields)
37 .map_err(PyPolarsErr::from)?;
38 Ok(e.into())
39 }
40}