Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(rust): Use Duration.is_zero instead of comparing Duration.duration_ns to 0 #16195

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-time/src/group_by/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Wrap<&DataFrame> {
options: &RollingGroupOptions,
) -> PolarsResult<(Series, Vec<Series>, 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",
);
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-time/src/windows/group_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -647,7 +647,7 @@ pub fn group_by_values(
iter.map(|result| result.map(|(offset, len)| [offset, len]))
.collect::<PolarsResult<_>>()
}
} else if offset.duration_ns() != 0
} else if !offset.is_zero()
|| closed_window == ClosedWindow::Right
|| closed_window == ClosedWindow::None
{
Expand Down