Function polars::export::arrow::compute::arithmetics::time::subtract_duration
source · [−]pub fn subtract_duration<T>(
time: &PrimitiveArray<T>,
duration: &PrimitiveArray<i64>
) -> PrimitiveArray<T> where
T: NativeType + Sub<T, Output = T>,
f64: AsPrimitive<T>,
This is supported on crate feature
compute_arithmetics
only.Expand description
Subtract a duration to a time array (Timestamp, Time and Date). The timeunit enum is used to scale correctly both arrays; adding seconds with seconds, or milliseconds with milliseconds.
Examples
use arrow2::compute::arithmetics::time::subtract_duration;
use arrow2::array::PrimitiveArray;
use arrow2::datatypes::{DataType, TimeUnit};
let timestamp = PrimitiveArray::from([
Some(100000i64),
Some(200000i64),
None,
Some(300000i64),
])
.to(DataType::Timestamp(
TimeUnit::Second,
Some("America/New_York".to_string()),
));
let duration = PrimitiveArray::from([Some(10i64), Some(20i64), None, Some(30i64)])
.to(DataType::Duration(TimeUnit::Second));
let result = subtract_duration(×tamp, &duration);
let expected = PrimitiveArray::from([
Some(99990i64),
Some(199980i64),
None,
Some(299970i64),
])
.to(DataType::Timestamp(
TimeUnit::Second,
Some("America/New_York".to_string()),
));
assert_eq!(result, expected);