From 77922c990f464416ab90970cd8bb5e369acd7511 Mon Sep 17 00:00:00 2001 From: ritchie Date: Mon, 9 Sep 2024 13:53:21 +0200 Subject: [PATCH] wip: [skip ci] --- .../src/executors/projection.rs | 4 ++-- .../src/executors/projection_utils.rs | 19 ++++++++++++------- crates/polars-plan/src/plans/aexpr/mod.rs | 1 + 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/crates/polars-mem-engine/src/executors/projection.rs b/crates/polars-mem-engine/src/executors/projection.rs index 43ffdd98c753..0f1ee259dc57 100644 --- a/crates/polars-mem-engine/src/executors/projection.rs +++ b/crates/polars-mem-engine/src/executors/projection.rs @@ -37,7 +37,7 @@ impl ProjectionExec { self.has_windows, self.options.run_parallel, )?; - check_expand_literals(selected_cols, df.is_empty(), self.options) + check_expand_literals(&self.expr, selected_cols, df.is_empty(), self.options) }); let df = POOL.install(|| iter.collect::>>())?; @@ -53,7 +53,7 @@ impl ProjectionExec { self.has_windows, self.options.run_parallel, )?; - check_expand_literals(selected_cols, df.is_empty(), self.options)? + check_expand_literals(&self.expr, selected_cols, df.is_empty(), self.options)? }; // this only runs during testing and check if the runtime type matches the predicted schema diff --git a/crates/polars-mem-engine/src/executors/projection_utils.rs b/crates/polars-mem-engine/src/executors/projection_utils.rs index 979c29321cb9..cd41e9260c92 100644 --- a/crates/polars-mem-engine/src/executors/projection_utils.rs +++ b/crates/polars-mem-engine/src/executors/projection_utils.rs @@ -243,6 +243,7 @@ pub(super) fn evaluate_physical_expressions( } pub(super) fn check_expand_literals( + phys_expr: &[Arc], mut selected_columns: Vec, zero_length: bool, options: ProjectionOptions, @@ -282,21 +283,25 @@ pub(super) fn check_expand_literals( if !all_equal_len && should_broadcast { selected_columns = selected_columns .into_iter() - .map(|series| { + .zip(phys_expr) + .map(|(series, phys)| { Ok(match series.len() { 0 if df_height == 1 => series, 1 => { if has_empty { - - polars_ensure!(df_height == 1, - ComputeError: "Series length {} doesn't match the DataFrame height of {}", - series.len(), df_height - ); - + polars_ensure!(df_height == 1, + ComputeError: "Series length {} doesn't match the DataFrame height of {}", + series.len(), df_height + ); series.slice(0, 0) } else if df_height == 1 { series } else { + polars_ensure!(phys.is_scalar(), + InvalidOperation: "Series length {} doesn't match the DataFrame height of {}\n\n\ + If you want this Series to be broadcasted, ensure it is a scalar (for instance by adding '.first()'.", + series.len(), df_height + ); series.new_from_index(0, df_height) } }, diff --git a/crates/polars-plan/src/plans/aexpr/mod.rs b/crates/polars-plan/src/plans/aexpr/mod.rs index 10ccc393a9d9..b13f06a3e523 100644 --- a/crates/polars-plan/src/plans/aexpr/mod.rs +++ b/crates/polars-plan/src/plans/aexpr/mod.rs @@ -22,6 +22,7 @@ use crate::constants::LEN; use crate::plans::Context; use crate::prelude::*; pub use scalar::is_scalar_ae; +pub use traverse::*; #[derive(Clone, Debug, IntoStaticStr)] #[cfg_attr(feature = "ir_serde", derive(Serialize, Deserialize))]