pola-rs/polars · error
Type {} does not support logical type {:?}
Error message
Type {} does not support logical type {:?} What it means
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.
Source
Thrown at crates/polars-arrow/src/scalar/primitive.rs:18
use super::Scalar;
use crate::datatypes::ArrowDataType;
use crate::types::NativeType;
/// The implementation of [`Scalar`] for primitive, semantically equivalent to [`Option<T>`]
/// with [`ArrowDataType`].
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PrimitiveScalar<T: NativeType> {
value: Option<T>,
dtype: ArrowDataType,
}
impl<T: NativeType> PrimitiveScalar<T> {
/// Returns a new [`PrimitiveScalar`].
#[inline]
pub fn new(dtype: ArrowDataType, value: Option<T>) -> Self {
if !dtype.to_physical_type().eq_primitive(T::PRIMITIVE) {
panic!(
"Type {} does not support logical type {:?}",
std::any::type_name::<T>(),
dtype
)
}
Self { value, dtype }
}
/// Returns the optional value.
#[inline]
pub fn value(&self) -> &Option<T> {
&self.value
}
/// Returns a new `PrimitiveScalar` with the same value but different [`ArrowDataType`]
/// # Panic
/// This function panics if the `dtype` is not valid for self's physical type `T`.
pub fn to(self, dtype: ArrowDataType) -> Self {View on GitHub (pinned to 9b5d73fd00)
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.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: 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.
Common situations: 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.
AI-assisted analysis of pola-rs/polars@9b5d73fd00 (2026-08-19).
Data as JSON: /api/errors/32af88d92d24fed5.
Report an issue: GitHub.