polars_python/lazyframe/
mod.rs

1mod exitable;
2#[cfg(feature = "pymethods")]
3mod general;
4mod optflags;
5#[cfg(feature = "pymethods")]
6mod serde;
7mod sink;
8pub mod visit;
9pub mod visitor;
10
11#[cfg(not(target_arch = "wasm32"))]
12pub use exitable::PyInProcessQuery;
13use polars::prelude::{Engine, LazyFrame, OptFlags};
14use pyo3::exceptions::PyValueError;
15use pyo3::pybacked::PyBackedStr;
16use pyo3::types::PyAnyMethods;
17use pyo3::{Bound, FromPyObject, PyAny, PyResult, pyclass};
18pub use sink::{PyPartitioning, SinkTarget};
19
20use crate::prelude::Wrap;
21
22#[pyclass]
23#[repr(transparent)]
24#[derive(Clone)]
25pub struct PyLazyFrame {
26    pub ldf: LazyFrame,
27}
28
29#[pyclass]
30#[repr(transparent)]
31#[derive(Clone)]
32pub struct PyOptFlags {
33    pub inner: OptFlags,
34}
35
36impl From<LazyFrame> for PyLazyFrame {
37    fn from(ldf: LazyFrame) -> Self {
38        PyLazyFrame { ldf }
39    }
40}
41
42impl From<PyLazyFrame> for LazyFrame {
43    fn from(pldf: PyLazyFrame) -> Self {
44        pldf.ldf
45    }
46}
47
48impl From<OptFlags> for PyOptFlags {
49    fn from(inner: OptFlags) -> Self {
50        PyOptFlags { inner }
51    }
52}
53
54impl<'py> FromPyObject<'py> for Wrap<Engine> {
55    fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
56        let parsed = ob
57            .extract::<PyBackedStr>()?
58            .parse()
59            .map_err(PyValueError::new_err)?;
60        Ok(Wrap(parsed))
61    }
62}