polars_lazy/frame/
python.rs

1use std::sync::Arc;
2
3use either::Either;
4use polars_core::schema::SchemaRef;
5use pyo3::PyObject;
6
7use self::python_dsl::{PythonOptionsDsl, PythonScanSource};
8use crate::prelude::*;
9
10impl 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}