polars_python/
utils.rs

1use pyo3::PyErr;
2
3use crate::error::PyPolarsErr;
4
5// was redefined because I could not get feature flags activated?
6#[macro_export]
7macro_rules! apply_method_all_arrow_series2 {
8    ($self:expr, $method:ident, $($args:expr),*) => {
9        match $self.dtype() {
10            DataType::Boolean => $self.bool().unwrap().$method($($args),*),
11            DataType::String => $self.str().unwrap().$method($($args),*),
12            DataType::UInt8 => $self.u8().unwrap().$method($($args),*),
13            DataType::UInt16 => $self.u16().unwrap().$method($($args),*),
14            DataType::UInt32 => $self.u32().unwrap().$method($($args),*),
15            DataType::UInt64 => $self.u64().unwrap().$method($($args),*),
16            DataType::Int8 => $self.i8().unwrap().$method($($args),*),
17            DataType::Int16 => $self.i16().unwrap().$method($($args),*),
18            DataType::Int32 => $self.i32().unwrap().$method($($args),*),
19            DataType::Int64 => $self.i64().unwrap().$method($($args),*),
20            DataType::Int128 => $self.i128().unwrap().$method($($args),*),
21            DataType::Float32 => $self.f32().unwrap().$method($($args),*),
22            DataType::Float64 => $self.f64().unwrap().$method($($args),*),
23            DataType::Date => $self.date().unwrap().$method($($args),*),
24            DataType::Datetime(_, _) => $self.datetime().unwrap().$method($($args),*),
25            DataType::List(_) => $self.list().unwrap().$method($($args),*),
26            DataType::Struct(_) => $self.struct_().unwrap().$method($($args),*),
27            dt => panic!("dtype {:?} not supported", dt)
28        }
29    }
30}
31
32/// Boilerplate for `|e| PyPolarsErr::from(e).into()`
33#[allow(unused)]
34pub(crate) fn to_py_err<E: Into<PyPolarsErr>>(e: E) -> PyErr {
35    e.into().into()
36}