From db8f50865af22d792c57feb47e95d2fc659a65b5 Mon Sep 17 00:00:00 2001 From: ritchie Date: Mon, 7 Oct 2024 09:08:46 +0200 Subject: [PATCH] feat: Improve scalar strict message --- .../src/executors/projection_utils.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/polars-mem-engine/src/executors/projection_utils.rs b/crates/polars-mem-engine/src/executors/projection_utils.rs index 6715796c5d30..d6c447a506b8 100644 --- a/crates/polars-mem-engine/src/executors/projection_utils.rs +++ b/crates/polars-mem-engine/src/executors/projection_utils.rs @@ -312,13 +312,15 @@ pub(super) fn check_expand_literals( } - if verify_scalar { - polars_ensure!(phys.is_scalar(), - ShapeMismatch: "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.name(), series.len(), df_height *(!has_empty as usize) - ); - + if verify_scalar && !phys.is_scalar() && std::env::var("POLARS_ALLOW_NON_SCALAR_EXP").as_deref() != Ok("1") { + let identifier = match phys.as_expression() { + Some(e) => format!("expression: {}", e), + None => "this Series".to_string(), + }; + polars_bail!(InvalidOperation: "Series {}, length {} doesn't match the DataFrame height of {}\n\n\ + If you want {} to be broadcasted, ensure it is a scalar (for instance by adding '.first()').", + series.name(), series.len(), df_height *(!has_empty as usize), identifier + ); } series.new_from_index(0, df_height * (!has_empty as usize) ) }