Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-python/src/lazyframe/mod.rs
7889 views
1
mod exitable;
2
#[cfg(feature = "pymethods")]
3
mod general;
4
mod optflags;
5
#[cfg(feature = "pymethods")]
6
mod serde;
7
mod sink;
8
pub mod visit;
9
pub mod visitor;
10
11
#[cfg(not(target_arch = "wasm32"))]
12
pub use exitable::PyInProcessQuery;
13
use parking_lot::RwLock;
14
use polars::prelude::{Engine, LazyFrame, OptFlags};
15
use pyo3::exceptions::PyValueError;
16
use pyo3::pybacked::PyBackedStr;
17
use pyo3::types::PyAnyMethods;
18
use pyo3::{Bound, FromPyObject, PyAny, PyResult, pyclass};
19
20
use crate::prelude::Wrap;
21
22
#[pyclass(frozen)]
23
#[repr(transparent)]
24
pub struct PyLazyFrame {
25
pub ldf: RwLock<LazyFrame>,
26
}
27
28
impl Clone for PyLazyFrame {
29
fn clone(&self) -> Self {
30
Self {
31
ldf: RwLock::new(self.ldf.read().clone()),
32
}
33
}
34
}
35
36
impl From<LazyFrame> for PyLazyFrame {
37
fn from(ldf: LazyFrame) -> Self {
38
PyLazyFrame {
39
ldf: RwLock::new(ldf),
40
}
41
}
42
}
43
44
impl From<PyLazyFrame> for LazyFrame {
45
fn from(pldf: PyLazyFrame) -> Self {
46
pldf.ldf.into_inner()
47
}
48
}
49
50
#[pyclass(frozen)]
51
#[repr(transparent)]
52
pub struct PyOptFlags {
53
pub inner: RwLock<OptFlags>,
54
}
55
56
impl Clone for PyOptFlags {
57
fn clone(&self) -> Self {
58
Self {
59
inner: RwLock::new(*self.inner.read()),
60
}
61
}
62
}
63
64
impl From<OptFlags> for PyOptFlags {
65
fn from(inner: OptFlags) -> Self {
66
PyOptFlags {
67
inner: RwLock::new(inner),
68
}
69
}
70
}
71
72
impl<'py> FromPyObject<'py> for Wrap<Engine> {
73
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
74
let parsed = ob
75
.extract::<PyBackedStr>()?
76
.parse()
77
.map_err(PyValueError::new_err)?;
78
Ok(Wrap(parsed))
79
}
80
}
81
82