Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-plan/src/plans/python/source.rs
6940 views
1
use std::sync::Arc;
2
3
use polars_core::schema::SchemaRef;
4
use polars_utils::python_function::PythonFunction;
5
#[cfg(feature = "ir_serde")]
6
use serde::{Deserialize, Serialize};
7
8
use crate::dsl::python_dsl::PythonScanSource;
9
use crate::plans::{ExprIR, PlSmallStr};
10
11
#[derive(Clone, PartialEq, Eq, Debug, Default)]
12
#[cfg_attr(feature = "ir_serde", derive(Serialize, Deserialize))]
13
pub struct PythonOptions {
14
/// A function that returns a Python Generator.
15
/// The generator should produce Polars DataFrame's.
16
pub scan_fn: Option<PythonFunction>,
17
/// Schema of the file.
18
pub schema: SchemaRef,
19
/// Schema the reader will produce when the file is read.
20
pub output_schema: Option<SchemaRef>,
21
// Projected column names.
22
pub with_columns: Option<Arc<[PlSmallStr]>>,
23
// Which interface is the python function.
24
pub python_source: PythonScanSource,
25
/// A `head` call passed to the reader.
26
pub n_rows: Option<usize>,
27
/// Optional predicate the reader must apply.
28
pub predicate: PythonPredicate,
29
/// Validate if the source gives the proper schema.
30
pub validate_schema: bool,
31
/// Whether this scan is free of side effects (allows for CSE when that is the case).
32
pub is_pure: bool,
33
}
34
35
#[derive(Clone, PartialEq, Eq, Debug, Default)]
36
#[cfg_attr(feature = "ir_serde", derive(Serialize, Deserialize))]
37
pub enum PythonPredicate {
38
// A pyarrow predicate python expression
39
// can be evaluated with python.eval
40
PyArrow(String),
41
Polars(ExprIR),
42
#[default]
43
None,
44
}
45
46