Skip to content

Commit

Permalink
polars_ensure
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Apr 15, 2024
1 parent 1e5835d commit 2d0b52c
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions crates/polars-plan/src/dsl/function_expr/ewm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ pub(super) fn ewm_mean_by(
DataType::Datetime(_, Some(time_zone)) => Some(time_zone.as_str()),
_ => None,
};
if half_life.negative() {
polars_bail!(InvalidOperation: "half_life cannot be negative");
}
if !half_life.is_constant_duration(time_zone) {
polars_bail!(InvalidOperation: "expected `half_life` to be a constant duration \
polars_ensure!(!half_life.negative(), InvalidOperation: "half_life cannot be negative");
polars_ensure!(half_life.is_constant_duration(time_zone),
InvalidOperation: "expected `half_life` to be a constant duration \
(i.e. one independent of differing month durations or of daylight savings time), got {}.\n\
\n\
You may want to try:\n\
- using `'730h'` instead of `'1mo'`\n\
- using `'24h'` instead of `'1d'` if your series is time-zone-aware", half_life);
}
// `half_life` is a constant duration so we can safely use `duration_ns()`.
let half_life = half_life.duration_ns();
let values = &s[0];
Expand Down

0 comments on commit 2d0b52c

Please sign in to comment.