Skip to content

Commit

Permalink
fix: Only allow list.to_struct to be elementwise when width is fixed
Browse files Browse the repository at this point in the history
Fixes #19549.
  • Loading branch information
coastalwhite committed Nov 7, 2024
1 parent a7672ac commit acf6344
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions crates/polars-plan/src/dsl/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,22 @@ impl ListNameSpace {
/// If this is incorrectly downstream operation may fail. For instance an `all().sum()` expression
/// will look in the current schema to determine which columns to select.
pub fn to_struct(self, args: ListToStructArgs) -> Expr {
self.0
.map_private(FunctionExpr::ListExpr(ListFunction::ToStruct(args)))
let collect_groups = match &args {
ListToStructArgs::FixedWidth(_) => ApplyOptions::ElementWise,

// If we have to infer the dtype it is not elementwise anymore, since different parts
// could infer to different widths.
ListToStructArgs::InferWidth { .. } => ApplyOptions::GroupWise,
};

Expr::Function {
input: vec![self.0],
function: FunctionExpr::ListExpr(ListFunction::ToStruct(args)),
options: FunctionOptions {
collect_groups,
..Default::default()
},
}
}

#[cfg(feature = "is_in")]
Expand Down

0 comments on commit acf6344

Please sign in to comment.