Path: blob/main/crates/polars-plan/src/plans/functions/python_udf.rs
6940 views
use super::*;12pub(super) fn call_python_udf(3function: &PythonFunction,4df: DataFrame,5validate_output: bool,6opt_schema: Option<SchemaRef>,7) -> PolarsResult<DataFrame> {8let expected_schema = if let Some(schema) = opt_schema {9Some(schema)10}11// only materialize if we validate the output12else if validate_output {13Some(df.schema().clone())14}15// do not materialize the schema, we will ignore it.16else {17None18};19let out = DataFrameUdf::call_udf(function, df)?;2021if validate_output {22let output_schema = out.schema();23let expected = expected_schema.unwrap();24if &expected != output_schema {25return Err(PolarsError::ComputeError(26format!(27"The output schema of 'LazyFrame.map' is incorrect. Expected: {expected:?}\n\28Got: {output_schema:?}"29)30.into(),31));32}33}34Ok(out)35}363738