{"record":{"id":"75435f8debbe0cc4","repo":"pola-rs/polars","slug":"invalid-from-physical-dtype-for","errorCode":null,"errorMessage":"invalid from_physical({dtype:?}) for {:?}","messagePattern":"invalid from_physical\\((.+?)\\) for (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/series/mod.rs","lineNumber":635,"sourceCode":"\n            #[cfg(feature = \"dtype-map\")]\n            (D::List(_), D::Map(_, _)) => {\n                use crate::chunked_array::logical::ensure_live_entries_non_null;\n\n                let storage = self.from_physical_unchecked(&dtype.map_storage_dtype().unwrap())?;\n                // Nulls that propagation left under null rows are legal; only live rows\n                // must own no null entry or key.\n                ensure_live_entries_non_null(storage.list().unwrap())?;\n                Ok(MapChunked::from_storage_unchecked(dtype.clone(), storage).into_series())\n            },\n            #[cfg(feature = \"dtype-extension\")]\n            (_, D::Extension(typ, storage)) => {\n                let storage_series = self.from_physical_unchecked(storage.as_ref())?;\n                let ext = ExtensionChunked::from_storage(typ.clone(), storage_series);\n                Ok(ext.into_series())\n            },\n\n            _ => panic!(\"invalid from_physical({dtype:?}) for {:?}\", self.dtype()),\n        }\n    }\n\n    #[cfg(feature = \"dtype-extension\")]\n    pub fn into_extension(self, typ: ExtensionTypeInstance) -> Series {\n        assert!(!self.dtype().is_extension());\n        let ext = ExtensionChunked::from_storage(typ, self);\n        ext.into_series()\n    }\n\n    /// Cast numerical types to f64, and keep floats as is.\n    pub fn to_float(&self) -> PolarsResult<Series> {\n        match self.dtype() {\n            DataType::Float32 | DataType::Float64 => Ok(self.clone()),\n            _ => self.cast_with_options(&DataType::Float64, CastOptions::Overflowing),\n        }\n    }\n","sourceCodeStart":617,"sourceCodeEnd":653,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/series/mod.rs#L617-L653","documentation":"Series::from_physical_unchecked panics when asked to reinterpret a series' physical representation into a logical dtype that the physical backing data does not support. It only handles the concrete (physical, logical) mappings it knows; anything else hits the catch-all panic.","triggerScenarios":"Calling from_physical_unchecked / try_from_physical_rec (or the internal callers restore_logical, repeat_by, scatter) with a dtype parameter that is not the physical counterpart of the series' actual dtype, e.g. converting Int64 physical to a datetime variant it cannot map.","commonSituations":"Hand-rolling dtype restoration after reading raw arrow data; custom extension-type storage dtype mismatches; version drift where a logical type gained new physical representations.","solutions":["Only call from_physical_unchecked with the exact physical dtype expected by the target logical type","Prefer the safe from_physical / cast_with_options API which returns PolarsResult instead of panicking","Verify self.dtype() before conversion and route unsupported dtypes through cast instead"],"exampleFix":"// before\nlet s = series.from_physical_unchecked(&DataType::Datetime(TimeUnit::Ns, None))?;\n// after\nlet s = series.cast_with_options(&DataType::Datetime(TimeUnit::Ns, None), CastOptions::NonStrict)?;","handlingStrategy":"try-catch","validationCode":"if !matches!(series.dtype(), DataType::Int32 | DataType::Int64 | DataType::Float64) { /* route to cast instead */ }","typeGuard":"fn is_physical(dtype: &DataType) -> bool { matches!(dtype, DataType::Int32 | DataType::Int64 | DataType::Float32 | DataType::Float64) }","tryCatchPattern":"// prefer safe API\nlet s: PolarsResult<Series> = series.cast_with_options(&target_dtype, CastOptions::NonStrict);","preventionTips":["Use cast/from_physical (Result-returning) instead of *_unchecked variants","Track physical<->logical mappings when restoring arrow data","Pin polars versions across services reading shared data"],"tags":["polars","rust","panic","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"}