Skip to content

Commit

Permalink
feat: Improve scalar strict message
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 24, 2024
1 parent e9d835d commit 75ab37f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions crates/polars-mem-engine/src/executors/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,16 @@ impl StackExec {
for (i, c) in res.iter().enumerate() {
let len = c.len();
if verify_scalar && len != df_height && len == 1 && df_width > 0 {
polars_ensure!(self.exprs[i].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()').",
c.name(), len, df_height
);
if !self.exprs[i].is_scalar() {
let identifier = match self.exprs[i].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()').",
c.name(), len, df_height, identifier
);
}
}
}
df._add_series(res, schema)?;
Expand Down

0 comments on commit 75ab37f

Please sign in to comment.