From 87b84c91daeb4c69d1cdda9e0ef3fd1863563ab0 Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli Date: Sat, 6 Apr 2024 15:05:50 +0300 Subject: [PATCH] perf: speed up offset_by when a single offset is passed (#15493) --- crates/polars-plan/src/dsl/function_expr/temporal.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/polars-plan/src/dsl/function_expr/temporal.rs b/crates/polars-plan/src/dsl/function_expr/temporal.rs index df4c0a688488..2a4e76fd326f 100644 --- a/crates/polars-plan/src/dsl/function_expr/temporal.rs +++ b/crates/polars-plan/src/dsl/function_expr/temporal.rs @@ -200,9 +200,12 @@ fn apply_offsets_to_datetime( _ => Ok(Int64Chunked::full_null(datetime.0.name(), offsets.len())), }, (_, 1) => match offsets.get(0) { - Some(offset) => datetime.0.try_apply_nonnull_values_generic(|v| { - offset_fn(&Duration::parse(offset), v, time_zone) - }), + Some(offset) => { + let offset = &Duration::parse(offset); + datetime + .0 + .try_apply_nonnull_values_generic(|v| offset_fn(offset, v, time_zone)) + }, _ => Ok(datetime.0.apply(|_| None)), }, _ => try_binary_elementwise(datetime, offsets, |timestamp_opt, offset_opt| {