pola-rs/polars · error
adding durations with different units is not supported here
Error message
adding durations with different units is not supported here
What it means
AnyValue::add supports Duration + Duration only when both share the same TimeUnit; mismatched units hit the unimplemented! guard because AnyValue carries no unit-normalization logic. Fire it by adding duration values of different units (e.g. ms + ns) through generic any-value arithmetic; normalize units upstream.
Source
Thrown at crates/polars-core/src/datatypes/any_value.rs:1046
}
#[must_use]
pub fn add(&self, rhs: &AnyValue) -> AnyValue<'static> {
use AnyValue::*;
match (self, rhs) {
(Null, r) => r.clone().into_static(),
(l, Null) => l.clone().into_static(),
(Int32(l), Int32(r)) => Int32(l + r),
(Int64(l), Int64(r)) => Int64(l + r),
(UInt32(l), UInt32(r)) => UInt32(l + r),
(UInt64(l), UInt64(r)) => UInt64(l + r),
(Float16(l), Float16(r)) => Float16(*l + *r),
(Float32(l), Float32(r)) => Float32(l + r),
(Float64(l), Float64(r)) => Float64(l + r),
#[cfg(feature = "dtype-duration")]
(Duration(l, lu), Duration(r, ru)) => {
if lu != ru {
unimplemented!("adding durations with different units is not supported here");
}
Duration(l + r, *lu)
},
#[cfg(feature = "dtype-decimal")]
(Decimal(l, lp, ls), Decimal(r, rp, rs)) => {
if (lp, ls) != (rp, rs) {
unimplemented!(
"adding decimals with different precisions/scales is not supported here"
);
}
Decimal(l + r, *lp, *ls)
},
_ => unimplemented!(),
}
}
View on GitHub (pinned to 68506541d2)
Solutions
- Cast both durations to the same time unit before adding.
- Convert one operand explicitly (e.g. ms -> us) so the units match.
Defensive patterns
Strategy: fallback
When it happens
Trigger: This panic/expect fires when execution reaches an unguarded state described by: "adding durations with different units is not supported here". Typical triggers: unsupported dtype or feature-gated code path reached at runtime, invalid user input or environment variable value, calling API methods in the wrong order or on mismatched types, or data (lengths, offsets, ranges) violating the function's preconditions.
Common situations: Encountered when input data or configuration does not meet the preconditions of the throwing code path ("adding durations with different units is not supported here"). Common cases: missing Cargo feature flags, mismatched dtypes/lengths between arrays or series, out-of-range temporal values, malformed environment variables, or operations on unsupported/complex nested types.
AI-assisted analysis of pola-rs/polars@68506541d2 (2026-08-19).
Data as JSON: /api/errors/d8b45ee7da26ac50.
Report an issue: GitHub.