pola-rs/polars · error

cannot create date from other type. dtype: {}

Error message

cannot create date from other type. dtype: {}

What it means

AnyValue::as_date only reinterprets Int32 (the physical date representation) and Null; any other variant panics naming its dtype. Fires when date conversion code calls as_date on a value that is not an Int32 physical date — cast the series to Date first rather than converting per-value.

Source

Thrown at crates/polars-core/src/datatypes/any_value.rs:953

    T: Into<AnyValue<'a>>,
{
    #[inline]
    fn from(a: Option<T>) -> Self {
        match a {
            None => AnyValue::Null,
            Some(v) => v.into(),
        }
    }
}

impl<'a> AnyValue<'a> {
    #[cfg(any(feature = "dtype-date", feature = "dtype-datetime"))]
    pub(crate) fn as_date(&self) -> AnyValue<'static> {
        match self {
            #[cfg(feature = "dtype-date")]
            AnyValue::Int32(v) => AnyValue::Date(*v),
            AnyValue::Null => AnyValue::Null,
            av => panic!("cannot create date from other type. dtype: {}", av.dtype()),
        }
    }

    #[cfg(feature = "dtype-datetime")]
    pub(crate) fn as_datetime(&self, tu: TimeUnit, tz: Option<&'a TimeZone>) -> AnyValue<'a> {
        match self {
            AnyValue::Int64(v) => AnyValue::Datetime(*v, tu, tz),
            AnyValue::Null => AnyValue::Null,
            av => panic!(
                "cannot create datetime from other type. dtype: {}",
                av.dtype()
            ),
        }
    }

    #[cfg(feature = "dtype-datetime")]
    pub(crate) fn as_datetime_owned(
        &self,

View on GitHub (pinned to 68506541d2)

Solutions

  1. Only construct a Date AnyValue from an Int32 (days since epoch) or another date value.
  2. Cast the source value to Int32 days-since-epoch first.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: This panic/expect fires when execution reaches an unguarded state described by: "cannot create date from other type. dtype: {}". 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 ("cannot create date from other type. dtype: {}"). 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@68506541d2 (2026-08-19). Data as JSON: /api/errors/01e728ba14d75622. Report an issue: GitHub.