Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-lazy/src/frame/python.rs
6939 views
1
use std::sync::Arc;
2
3
use either::Either;
4
use polars_core::schema::SchemaRef;
5
use pyo3::PyObject;
6
7
use self::python_dsl::{PythonOptionsDsl, PythonScanSource};
8
use crate::prelude::*;
9
10
impl LazyFrame {
11
pub fn scan_from_python_function(
12
schema: Either<PyObject, SchemaRef>,
13
scan_fn: PyObject,
14
pyarrow: bool,
15
// Validate that the source gives the proper schema
16
validate_schema: bool,
17
is_pure: bool,
18
) -> Self {
19
DslPlan::PythonScan {
20
options: PythonOptionsDsl {
21
// Should be a python function that returns a generator
22
scan_fn: Some(scan_fn.into()),
23
schema_fn: Some(SpecialEq::new(Arc::new(schema.map_left(|obj| obj.into())))),
24
python_source: if pyarrow {
25
PythonScanSource::Pyarrow
26
} else {
27
PythonScanSource::IOPlugin
28
},
29
validate_schema,
30
is_pure,
31
},
32
}
33
.into()
34
}
35
}
36
37