pola-rs/polars · error
adding decimals with different precisions/scales is not supp
Error message
adding decimals with different precisions/scales is not supported here
What it means
AnyValue::add for Decimal values requires equal precision/scale on both operands; differing metadata hits this unimplemented! guard since AnyValue addition does not rescale decimals. Ensure operands share precision/scale (cast one side) before generic addition.
Source
Thrown at crates/polars-core/src/datatypes/any_value.rs:1054
(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!(),
}
}
#[inline]
pub fn as_borrowed(&self) -> AnyValue<'_> {
match self {
AnyValue::BinaryOwned(data) => AnyValue::Binary(data),
AnyValue::StringOwned(data) => AnyValue::String(data.as_str()),
#[cfg(feature = "dtype-datetime")]
AnyValue::DatetimeOwned(v, tu, tz) => {
AnyValue::Datetime(*v, *tu, tz.as_ref().map(AsRef::as_ref))View on GitHub (pinned to 68506541d2)
Solutions
- Align precision and scale of both decimals before adding (e.g. via cast to a common decimal dtype).
- Perform the arithmetic in floating point if exact decimal alignment is not required.
Defensive patterns
Strategy: fallback
When it happens
Trigger: This panic/expect fires when execution reaches an unguarded state described by: "adding decimals with different precisions/scales 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 decimals with different precisions/scales 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/89b1021d45dcb1c1.
Report an issue: GitHub.