{"record":{"id":"1c7882c913d6a428","repo":"pola-rs/polars","slug":"into-decimal-precision-scale-not-implement","errorCode":null,"errorMessage":"into_decimal({precision:?}, {scale}) not implemented for {dt:?}","messagePattern":"into_decimal\\((.+?), (.+?)\\) not implemented for (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/series/mod.rs","lineNumber":937,"sourceCode":"    pub fn strict_cast(&self, dtype: &DataType) -> PolarsResult<Series> {\n        self.cast_with_options(dtype, CastOptions::Strict)\n    }\n\n    #[cfg(feature = \"dtype-decimal\")]\n    pub fn into_decimal(self, precision: usize, scale: usize) -> PolarsResult<Series> {\n        match self.dtype() {\n            DataType::Int128 => Ok(self\n                .i128()\n                .unwrap()\n                .clone()\n                .into_decimal(precision, scale)?\n                .into_series()),\n            DataType::Decimal(cur_prec, cur_scale)\n                if scale == *cur_scale && precision >= *cur_prec =>\n            {\n                Ok(self)\n            },\n            dt => panic!(\"into_decimal({precision:?}, {scale}) not implemented for {dt:?}\"),\n        }\n    }\n\n    #[cfg(feature = \"dtype-time\")]\n    pub fn into_time(self) -> Series {\n        match self.dtype() {\n            DataType::Int64 => self.i64().unwrap().clone().into_time().into_series(),\n            DataType::Time => self\n                .time()\n                .unwrap()\n                .physical()\n                .clone()\n                .into_time()\n                .into_series(),\n            dt => panic!(\"date not implemented for {dt:?}\"),\n        }\n    }\n","sourceCodeStart":919,"sourceCodeEnd":955,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/series/mod.rs#L919-L955","documentation":"Series::into_decimal panics when the series' dtype cannot be converted to Decimal(precision, scale). Only Integers/Floats into decimal, or an existing decimal whose scale matches and whose precision fits within the target precision, are accepted.","triggerScenarios":"Calling into_decimal(precision, scale) on a series whose dtype is not an integer/float/decimal, or on a decimal with scale != target scale, or with precision < current decimal precision.","commonSituations":"Shrinking decimal precision (e.g. Decimal(38,10) into precision 20) which would overflow; converting string or date series to decimal; mismatched scale expectations after reading parquet.","solutions":["Ensure the source dtype is Int/Float/Decimal before calling into_decimal","Match the target scale exactly to the existing decimal's scale, and use precision >= current precision","Use strict_cast(&DataType::Decimal(precision, scale)) which returns a PolarsResult instead of panicking"],"exampleFix":"// before\nlet s = series.into_decimal(Some(20), 10)?; // precision shrink -> panic\n// after\nlet s = series.strict_cast(&DataType::Decimal(Some(38), 10))?;","handlingStrategy":"type-guard","validationCode":"match s.dtype() { DataType::Int32 | DataType::Int64 | DataType::Float64 | DataType::Decimal(_, _) => {}, _ => return Err(...) }","typeGuard":"fn decidable_to_decimal(dt: &DataType) -> bool { matches!(dt, DataType::Int32 | DataType::Int64 | DataType::UInt32 | DataType::UInt64 | DataType::Float32 | DataType::Float64 | DataType::Decimal(_, _)) }","tryCatchPattern":"let s: PolarsResult<Series> = series.strict_cast(&DataType::Decimal(Some(prec), scale));","preventionTips":["Verify current decimal scale/precision before into_decimal","Never shrink decimal precision; use cast with overflow semantics","Keep numeric parsing pipeline dtypes documented"],"tags":["polars","rust","panic","decimal","dtype"],"backgroundTag":"unsupported-dtype","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"}