Skip to content

Commit

Permalink
feat: allow no-op round/ceil/floor on int types (#17241)
Browse files Browse the repository at this point in the history
  • Loading branch information
orlp authored Jun 27, 2024
1 parent b428ec3 commit c45e5ec
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crates/polars-ops/src/series/ops/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ pub trait RoundSeries: SeriesSealed {
Ok(s)
};
}
polars_bail!(opq = round, s.dtype());

polars_ensure!(s.dtype().is_numeric(), InvalidOperation: "round can only be used on numeric types" );
Ok(s.clone())
}

fn round_sig_figs(&self, digits: i32) -> PolarsResult<Series> {
Expand Down Expand Up @@ -68,7 +70,9 @@ pub trait RoundSeries: SeriesSealed {
let s = ca.apply_values(|val| val.floor()).into_series();
return Ok(s);
}
polars_bail!(opq = floor, s.dtype());

polars_ensure!(s.dtype().is_numeric(), InvalidOperation: "floor can only be used on numeric types" );
Ok(s.clone())
}

/// Ceil underlying floating point array to the highest integers smaller or equal to the float value.
Expand All @@ -83,7 +87,9 @@ pub trait RoundSeries: SeriesSealed {
let s = ca.apply_values(|val| val.ceil()).into_series();
return Ok(s);
}
polars_bail!(opq = ceil, s.dtype());

polars_ensure!(s.dtype().is_numeric(), InvalidOperation: "ceil can only be used on numeric types" );
Ok(s.clone())
}
}

Expand Down

0 comments on commit c45e5ec

Please sign in to comment.