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
8390 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::prelude::*;
17
use pyo3::pybacked::PyBackedStr;
18
19
use crate::prelude::Wrap;
20
21
#[pyclass(frozen)]
22
#[repr(transparent)]
23
pub struct PyLazyFrame {
24
pub ldf: RwLock<LazyFrame>,
25
}
26
27
impl Clone for PyLazyFrame {
28
fn clone(&self) -> Self {
29
Self {
30
ldf: RwLock::new(self.ldf.read().clone()),
31
}
32
}
33
}
34
35
impl From<LazyFrame> for PyLazyFrame {
36
fn from(ldf: LazyFrame) -> Self {
37
PyLazyFrame {
38
ldf: RwLock::new(ldf),
39
}
40
}
41
}
42
43
impl From<PyLazyFrame> for LazyFrame {
44
fn from(pldf: PyLazyFrame) -> Self {
45
pldf.ldf.into_inner()
46
}
47
}
48
49
#[pyclass(frozen)]
50
#[repr(transparent)]
51
pub struct PyOptFlags {
52
pub inner: RwLock<OptFlags>,
53
}
54
55
impl Clone for PyOptFlags {
56
fn clone(&self) -> Self {
57
Self {
58
inner: RwLock::new(*self.inner.read()),
59
}
60
}
61
}
62
63
impl From<OptFlags> for PyOptFlags {
64
fn from(inner: OptFlags) -> Self {
65
PyOptFlags {
66
inner: RwLock::new(inner),
67
}
68
}
69
}
70
71
impl<'a, 'py> FromPyObject<'a, 'py> for Wrap<Engine> {
72
type Error = PyErr;
73
74
fn extract(ob: Borrowed<'a, 'py, PyAny>) -> PyResult<Self> {
75
let parsed = ob
76
.extract::<PyBackedStr>()?
77
.parse()
78
.map_err(PyValueError::new_err)?;
79
Ok(Wrap(parsed))
80
}
81
}
82
83