Skip to content

Commit

Permalink
refactor(rust): Fix zero-length len (pola-rs#18817)
Browse files Browse the repository at this point in the history
  • Loading branch information
orlp authored Sep 19, 2024
1 parent 9384945 commit 506f927
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crates/polars-expr/src/reduce/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ pub fn into_reduction(
_ => unreachable!(),
},
AExpr::Len => {
// Compute length on the first column, or if none exist we'll never
// be called and correctly return 0 as length anyway.
// Compute length on the first column, or if none exist we'll use
// a zero-length dummy series.
let out: Box<dyn Reduction> = Box::new(LenReduce::new());
let expr = if let Some(first_column) = schema.iter_names().next() {
expr_arena.add(AExpr::Column(first_column.as_str().into()))
} else {
expr_arena.add(AExpr::Literal(LiteralValue::Null))
let dummy = Series::new_null(PlSmallStr::from_static("dummy"), 0);
expr_arena.add(AExpr::Literal(LiteralValue::Series(SpecialEq::new(dummy))))
};
(out, expr)
},
Expand Down

0 comments on commit 506f927

Please sign in to comment.