Skip to content

Commit

Permalink
feat: Improve scalar strict message (#19117)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Oct 7, 2024
1 parent d31bbf4 commit 018dfd1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions crates/polars-mem-engine/src/executors/projection_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(ShapeMismatch: "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) )
}
Expand Down

0 comments on commit 018dfd1

Please sign in to comment.