polars_python/lazyframe/
optflags.rs1use polars::prelude::OptFlags;
2use pyo3::pymethods;
3
4use super::PyOptFlags;
5
6macro_rules! flag_getter_setters {
7 ($(($flag:ident, $getter:ident, $setter:ident, clear=$clear:literal))+) => {
8 #[pymethods]
9 impl PyOptFlags {
10 #[staticmethod]
11 pub fn empty() -> Self {
12 Self {
13 inner: OptFlags::empty()
14 }
15 }
16
17 #[staticmethod]
18 #[allow(clippy::should_implement_trait)]
19 pub fn default() -> Self {
20 Self { inner: OptFlags::default() }
21 }
22
23 pub fn no_optimizations(&mut self) {
24 $(if $clear {
25 self.inner.remove(OptFlags::$flag);
26 })+
27 }
28
29 pub fn copy(&self) -> Self {
30 Self { inner: self.inner }
31 }
32
33 $(
34 #[getter]
35 fn $getter(&self) -> bool {
36 self.inner.contains(OptFlags::$flag)
37 }
38 #[setter]
39 fn $setter(&mut self, value: bool) {
40 self.inner.set(OptFlags::$flag, value)
41 }
42 )+
43 }
44 };
45}
46
47flag_getter_setters! {
48 (TYPE_COERCION, get_type_coercion, set_type_coercion, clear=false)
49 (TYPE_CHECK, get_type_check, set_type_check, clear=false)
50
51 (PROJECTION_PUSHDOWN, get_projection_pushdown, set_projection_pushdown, clear=true)
52 (PREDICATE_PUSHDOWN, get_predicate_pushdown, set_predicate_pushdown, clear=true)
53 (CLUSTER_WITH_COLUMNS, get_cluster_with_columns, set_cluster_with_columns, clear=true)
54 (SIMPLIFY_EXPR, get_simplify_expression, set_simplify_expression, clear=true)
55 (SLICE_PUSHDOWN, get_slice_pushdown, set_slice_pushdown, clear=true)
56 (COMM_SUBPLAN_ELIM, get_comm_subplan_elim, set_comm_subplan_elim, clear=true)
57 (COMM_SUBEXPR_ELIM, get_comm_subexpr_elim, set_comm_subexpr_elim, clear=true)
58 (COLLAPSE_JOINS, get_collapse_joins, set_collapse_joins, clear=true)
59 (CHECK_ORDER_OBSERVE, get_check_order_observe, set_check_order_observe, clear=true)
60 (FAST_PROJECTION, get_fast_projection, set_fast_projection, clear=true)
61
62 (EAGER, get_eager, set_eager, clear=true)
63 (STREAMING, get_old_streaming, set_old_streaming, clear=true)
64 (NEW_STREAMING, get_streaming, set_streaming, clear=true)
65}