Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve scalar strict message #18904

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 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,19 @@ 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
);
#[allow(clippy::collapsible_if)]
if !self.exprs[i].is_scalar()
&& std::env::var("POLARS_ALLOW_NON_SCALAR_EXP").as_deref() != Ok("1")
{
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
Loading