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
  • Loading branch information
coastalwhite authored Nov 8, 2024
1 parent 235f240 commit 8c41ae4
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 8c41ae4

Please sign in to comment.