{"record":{"id":"32af88d92d24fed5","repo":"pola-rs/polars","slug":"type-does-not-support-logical-type","errorCode":null,"errorMessage":"Type {} does not support logical type {:?}","messagePattern":"Type (.+?) does not support logical type (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-arrow/src/scalar/primitive.rs","lineNumber":18,"sourceCode":"use super::Scalar;\nuse crate::datatypes::ArrowDataType;\nuse crate::types::NativeType;\n\n/// The implementation of [`Scalar`] for primitive, semantically equivalent to [`Option<T>`]\n/// with [`ArrowDataType`].\n#[derive(Debug, Clone, PartialEq, Eq)]\npub struct PrimitiveScalar<T: NativeType> {\n    value: Option<T>,\n    dtype: ArrowDataType,\n}\n\nimpl<T: NativeType> PrimitiveScalar<T> {\n    /// Returns a new [`PrimitiveScalar`].\n    #[inline]\n    pub fn new(dtype: ArrowDataType, value: Option<T>) -> Self {\n        if !dtype.to_physical_type().eq_primitive(T::PRIMITIVE) {\n            panic!(\n                \"Type {} does not support logical type {:?}\",\n                std::any::type_name::<T>(),\n                dtype\n            )\n        }\n        Self { value, dtype }\n    }\n\n    /// Returns the optional value.\n    #[inline]\n    pub fn value(&self) -> &Option<T> {\n        &self.value\n    }\n\n    /// Returns a new `PrimitiveScalar` with the same value but different [`ArrowDataType`]\n    /// # Panic\n    /// This function panics if the `dtype` is not valid for self's physical type `T`.\n    pub fn to(self, dtype: ArrowDataType) -> Self {","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/crates/polars-arrow/src/scalar/primitive.rs#L1-L36","documentation":"Documented panic of PrimitiveScalar::new: the ArrowDataType's physical type does not match the Rust native type T being stored (e.g. building a PrimitiveScalar<i32> with an Int64 dtype). The scalar would be unsound to read back. Pass a dtype whose to_physical_type() equals T::PRIMITIVE.","triggerScenarios":"This panic/expect fires when execution reaches an unguarded state described by: \"Type {} does not support logical 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 (\"Type {} does not support logical 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":["Use a physical primitive type that supports the requested logical type (e.g. Int32 for Date32, Int64 for Timestamp).","Cast the scalar to a compatible primitive type before applying the logical-type conversion."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9b5d73fd00236295624374b075d16b1fe6ec6df9","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}