Skip to content

Commit

Permalink
fast path all null
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 11, 2024
1 parent b1f4356 commit 409233c
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions crates/polars-ops/src/series/ops/cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,19 @@ pub fn qcut(
) -> PolarsResult<Series> {
polars_ensure!(!probs.iter().any(|x| x.is_nan()), ComputeError: "quantiles cannot be NaN");

if s.null_count() == s.len() {
// If we only have nulls we don't have any breakpoints.
return Ok(Series::full_null(
s.name().clone(),
s.len(),
&DataType::Categorical(None, Default::default()),
));
}

let s = s.cast(&DataType::Float64)?;
let s2 = s.sort(SortOptions::default())?;
let ca = s2.f64()?;

if ca.null_count() == ca.len() {
// If we only have nulls we don't have any breakpoints.
return cut(
&s,
vec![],
None::<Vec<PlSmallStr>>,
left_closed,
include_breaks,
);
}

let f = |&p| {
ca.quantile(p, QuantileInterpolOptions::Linear)
.unwrap()
Expand Down

0 comments on commit 409233c

Please sign in to comment.