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    ) -> Self {
18        DslPlan::PythonScan {
19            options: PythonOptionsDsl {
20                // Should be a python function that returns a generator
21                scan_fn: Some(scan_fn.into()),
22                schema_fn: Some(SpecialEq::new(Arc::new(schema.map_left(|obj| obj.into())))),
23                python_source: if pyarrow {
24                    PythonScanSource::Pyarrow
25                } else {
26                    PythonScanSource::IOPlugin
27                },
28                validate_schema,
29            },
30        }
31        .into()
32    }
33}