Skip to content

Commit

Permalink
wip: [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 9, 2024
1 parent 3f12f7e commit 77922c9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions crates/polars-mem-engine/src/executors/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<PolarsResult<Vec<_>>>())?;
Expand All @@ -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
Expand Down
19 changes: 12 additions & 7 deletions crates/polars-mem-engine/src/executors/projection_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ pub(super) fn evaluate_physical_expressions(
}

pub(super) fn check_expand_literals(
phys_expr: &[Arc<dyn PhysicalExpr>],
mut selected_columns: Vec<Series>,
zero_length: bool,
options: ProjectionOptions,
Expand Down Expand Up @@ -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)
}
},
Expand Down
1 change: 1 addition & 0 deletions crates/polars-plan/src/plans/aexpr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down

0 comments on commit 77922c9

Please sign in to comment.