{"record":{"id":"89b1021d45dcb1c1","repo":"pola-rs/polars","slug":"adding-decimals-with-different-precisions-scales-i","errorCode":null,"errorMessage":"adding decimals with different precisions/scales is not supported here","messagePattern":"adding decimals with different precisions/scales is not supported here","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/datatypes/any_value.rs","lineNumber":1054,"sourceCode":"            (Int32(l), Int32(r)) => Int32(l + r),\n            (Int64(l), Int64(r)) => Int64(l + r),\n            (UInt32(l), UInt32(r)) => UInt32(l + r),\n            (UInt64(l), UInt64(r)) => UInt64(l + r),\n            (Float16(l), Float16(r)) => Float16(*l + *r),\n            (Float32(l), Float32(r)) => Float32(l + r),\n            (Float64(l), Float64(r)) => Float64(l + r),\n            #[cfg(feature = \"dtype-duration\")]\n            (Duration(l, lu), Duration(r, ru)) => {\n                if lu != ru {\n                    unimplemented!(\"adding durations with different units is not supported here\");\n                }\n\n                Duration(l + r, *lu)\n            },\n            #[cfg(feature = \"dtype-decimal\")]\n            (Decimal(l, lp, ls), Decimal(r, rp, rs)) => {\n                if (lp, ls) != (rp, rs) {\n                    unimplemented!(\n                        \"adding decimals with different precisions/scales is not supported here\"\n                    );\n                }\n\n                Decimal(l + r, *lp, *ls)\n            },\n            _ => unimplemented!(),\n        }\n    }\n\n    #[inline]\n    pub fn as_borrowed(&self) -> AnyValue<'_> {\n        match self {\n            AnyValue::BinaryOwned(data) => AnyValue::Binary(data),\n            AnyValue::StringOwned(data) => AnyValue::String(data.as_str()),\n            #[cfg(feature = \"dtype-datetime\")]\n            AnyValue::DatetimeOwned(v, tu, tz) => {\n                AnyValue::Datetime(*v, *tu, tz.as_ref().map(AsRef::as_ref))","sourceCodeStart":1036,"sourceCodeEnd":1072,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/datatypes/any_value.rs#L1036-L1072","documentation":"`AnyValue::add` for Decimal values requires both operands to have identical precision and scale; otherwise the result's scale is ambiguous. Differing (precision, scale) triggers an `unimplemented!` panic because this low-level path performs no rescaling.","triggerScenarios":"Using the `+` operator on two AnyValue::Decimal values whose (precision, scale) tuples differ — e.g. `Decimal(100, 10, 2) + Decimal(5, 10, 0)`.","commonSituations":"Adding decimal columns that were constructed with different scales (e.g. parsed from CSV strings with different decimal places, or defined with different dtypes), then summed row-wise or combined in expressions.","solutions":["Cast both decimal operands to the same DataType::Decimal(precision, scale) before adding","Standardize decimal scale at data-ingestion/parse time","Use the Series-level arithmetic which handles decimal rescaling, instead of AnyValue-level addition"],"exampleFix":"// before\nlet sum = dec_10_2.add(&dec_10_0); // unimplemented! panic\n// after\nlet dec_10_0_rescaled = dec_10_0.cast(&DataType::Decimal(Some(10), Some(2)));\nlet sum = dec_10_2.add(&dec_10_0_rescaled);","handlingStrategy":"validation","validationCode":"fn can_add_decimals(l: &AnyValue, r: &AnyValue) -> bool {\n    match (l, r) {\n        (AnyValue::Decimal(_, lp, ls), AnyValue::Decimal(_, rp, rs)) => (lp, ls) == (rp, rs),\n        _ => true,\n    }\n}","typeGuard":"fn same_decimal_shape(l: &AnyValue, r: &AnyValue) -> bool {\n    matches!((l, r), (AnyValue::Decimal(_, lp, ls), AnyValue::Decimal(_, rp, rs)) if (lp, ls) == (rp, rs))\n}","tryCatchPattern":null,"preventionTips":["Cast decimal operands to identical (precision, scale) before adding","Normalize decimal scale at parse/ingestion time","Prefer Series-level decimal arithmetic which rescales automatically"],"tags":["rust","polars","decimal","arithmetic"],"backgroundTag":"unsupported-operation","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}