diff --git a/crates/polars-ops/src/chunked_array/datetime/replace_time_zone.rs b/crates/polars-ops/src/chunked_array/datetime/replace_time_zone.rs index 90e50a6e625c..cc3713d91562 100644 --- a/crates/polars-ops/src/chunked_array/datetime/replace_time_zone.rs +++ b/crates/polars-ops/src/chunked_array/datetime/replace_time_zone.rs @@ -4,7 +4,7 @@ use arrow::temporal_conversions::{ use chrono::NaiveDateTime; use chrono_tz::{Tz, UTC}; use polars_arrow::kernels::convert_to_naive_local; -use polars_core::chunked_array::ops::arity::try_binary_elementwise_values; +use polars_core::chunked_array::ops::arity::try_binary_elementwise; use polars_core::prelude::*; fn parse_time_zone(s: &str) -> PolarsResult { @@ -51,14 +51,17 @@ pub fn replace_time_zone( }), _ => Ok(datetime.0.apply(|_| None)), }, - _ => { - try_binary_elementwise_values(datetime, ambiguous, |timestamp: i64, ambiguous: &str| { - let ndt = timestamp_to_datetime(timestamp); - Ok::(datetime_to_timestamp(convert_to_naive_local( - &from_tz, &to_tz, ndt, ambiguous, - )?)) - }) - }, + _ => try_binary_elementwise(datetime, ambiguous, |timestamp_opt, ambiguous_opt| { + match (timestamp_opt, ambiguous_opt) { + (Some(timestamp), Some(ambiguous)) => { + let ndt = timestamp_to_datetime(timestamp); + Ok(Some(datetime_to_timestamp(convert_to_naive_local( + &from_tz, &to_tz, ndt, ambiguous, + )?))) + }, + _ => Ok(None), + } + }), }; let mut out = out?.into_datetime(datetime.time_unit(), time_zone.map(|x| x.to_string())); if from_time_zone == "UTC" && ambiguous.len() == 1 && ambiguous.get(0).unwrap() == "raise" { diff --git a/crates/polars-plan/src/dsl/function_expr/temporal.rs b/crates/polars-plan/src/dsl/function_expr/temporal.rs index 2de19d5b5ab7..15e601dd7dbb 100644 --- a/crates/polars-plan/src/dsl/function_expr/temporal.rs +++ b/crates/polars-plan/src/dsl/function_expr/temporal.rs @@ -1,7 +1,7 @@ #[cfg(feature = "date_offset")] use polars_arrow::time_zone::Tz; #[cfg(feature = "date_offset")] -use polars_core::chunked_array::ops::arity::try_binary_elementwise_values; +use polars_core::chunked_array::ops::arity::try_binary_elementwise; #[cfg(feature = "date_offset")] use polars_time::prelude::*; @@ -139,9 +139,13 @@ fn apply_offsets_to_datetime( .try_apply(|v| offset_fn(&Duration::parse(offset), v, time_zone)), _ => Ok(datetime.0.apply(|_| None)), }, - _ => try_binary_elementwise_values(datetime, offsets, |timestamp: i64, offset: &str| { - let offset = Duration::parse(offset); - offset_fn(&offset, timestamp, time_zone) + _ => try_binary_elementwise(datetime, offsets, |timestamp_opt, offset_opt| { + match (timestamp_opt, offset_opt) { + (Some(timestamp), Some(offset)) => { + offset_fn(&Duration::parse(offset), timestamp, time_zone).map(Some) + }, + _ => Ok(None), + } }), } }