{"record":{"id":"c338dcf645bd1cf9","repo":"pola-rs/polars","slug":"cannot-unpack-series-into-matching-type","errorCode":null,"errorMessage":"cannot unpack series {:?} into matching type {:?}","messagePattern":"cannot unpack series (.+?) into matching type (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/chunked_array/mod.rs","lineNumber":465,"sourceCode":"    ///\n    /// # Safety\n    ///\n    /// This is unsafe as the dtype may be incorrect and\n    /// is assumed to be correct in other safe code.\n    pub(crate) unsafe fn unpack_series_matching_physical_type<'a>(\n        &self,\n        series: &'a Series,\n    ) -> &'a ChunkedArray<T> {\n        let series_trait = &**series;\n        if self.dtype() == series.dtype() {\n            &*(series_trait as *const dyn SeriesTrait as *const ChunkedArray<T>)\n        } else {\n            use DataType::*;\n            match (self.dtype(), series.dtype()) {\n                (Int64, Datetime(_, _)) | (Int64, Duration(_)) | (Int32, Date) => {\n                    &*(series_trait as *const dyn SeriesTrait as *const ChunkedArray<T>)\n                },\n                _ => panic!(\n                    \"cannot unpack series {:?} into matching type {:?}\",\n                    series,\n                    self.dtype()\n                ),\n            }\n        }\n    }\n\n    /// Returns an iterator over the lengths of the chunks of the array.\n    pub fn chunk_lengths(&self) -> ChunkLenIter<'_> {\n        self.chunks.iter().map(|chunk| chunk.len())\n    }\n\n    /// A reference to the chunks\n    #[inline]\n    pub fn chunks(&self) -> &Vec<ArrayRef> {\n        &self.chunks\n    }","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/pola-rs/polars/blob/68506541d2de983056c9eb244e1ea05fab377dfc/crates/polars-core/src/chunked_array/mod.rs#L447-L483","documentation":"unsafe unpack_series_matching_physical_type was called on a Series whose dtype is not physically compatible with the target ChunkedArray type (neither equal nor a known physical/logical pair); the cast would be unsound so it panics.","triggerScenarios":"This panic/expect fires when execution reaches an unguarded state described by: \"cannot unpack series {:?} into matching type {:?}\". 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.","commonSituations":"Encountered when input data or configuration does not meet the preconditions of the throwing code path (\"cannot unpack series {:?} into matching type {:?}\"). 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.","solutions":["Match the series dtype to the type you unpack into (e.g. call `.i32()` only on Int32 series).","Cast the series to the target dtype before unpacking."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"68506541d2de983056c9eb244e1ea05fab377dfc","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}