From 5072a64a6ec910e058b306f5c89fbd631c754c94 Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 13 May 2024 13:35:19 +0100 Subject: [PATCH] chore(rust): use Duration.is_zero instead of comparing Duration.duration_ns to 0 --- .../polars-time/src/chunkedarray/rolling_window/dispatch.rs | 2 +- crates/polars-time/src/group_by/dynamic.rs | 2 +- crates/polars-time/src/windows/group_by.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/polars-time/src/chunkedarray/rolling_window/dispatch.rs b/crates/polars-time/src/chunkedarray/rolling_window/dispatch.rs index 5feb3f9f99cb..eaf503db5a68 100644 --- a/crates/polars-time/src/chunkedarray/rolling_window/dispatch.rs +++ b/crates/polars-time/src/chunkedarray/rolling_window/dispatch.rs @@ -83,7 +83,7 @@ where } let ca = ca.rechunk(); ensure_duration_matches_data_type(options.window_size, by.dtype(), "window_size")?; - polars_ensure!(options.window_size.duration_ns()>0 && !options.window_size.negative, InvalidOperation: "`window_size` must be strictly positive"); + polars_ensure!(!options.window_size.is_zero() && !options.window_size.negative, InvalidOperation: "`window_size` must be strictly positive"); if by.is_sorted_flag() != IsSorted::Ascending && options.warn_if_unsorted { polars_warn!(format!( "Series is not known to be sorted by `by` column in `rolling_*_by` operation.\n\ diff --git a/crates/polars-time/src/group_by/dynamic.rs b/crates/polars-time/src/group_by/dynamic.rs index 589119440ec4..30c352b62bb0 100644 --- a/crates/polars-time/src/group_by/dynamic.rs +++ b/crates/polars-time/src/group_by/dynamic.rs @@ -128,7 +128,7 @@ impl Wrap<&DataFrame> { options: &RollingGroupOptions, ) -> PolarsResult<(Series, Vec, GroupsProxy)> { polars_ensure!( - options.period.duration_ns() > 0 && !options.period.negative, + !options.period.is_zero() && !options.period.negative, ComputeError: "rolling window period should be strictly positive", ); diff --git a/crates/polars-time/src/windows/group_by.rs b/crates/polars-time/src/windows/group_by.rs index 1754cde91865..ce4d9c62767b 100644 --- a/crates/polars-time/src/windows/group_by.rs +++ b/crates/polars-time/src/windows/group_by.rs @@ -576,7 +576,7 @@ pub fn group_by_values( let run_parallel = !POOL.current_thread_has_pending_tasks().unwrap_or(false); // we have a (partial) lookbehind window - if offset.negative && offset.duration_ns() > 0 { + if offset.negative && !offset.is_zero() { // lookbehind if offset.duration_ns() == period.duration_ns() { // t is right at the end of the window @@ -647,7 +647,7 @@ pub fn group_by_values( iter.map(|result| result.map(|(offset, len)| [offset, len])) .collect::>() } - } else if offset.duration_ns() != 0 + } else if !offset.is_zero() || closed_window == ClosedWindow::Right || closed_window == ClosedWindow::None {