pola-rs/polars · error
cannot create datetime from other type. dtype: {}
Error message
cannot create datetime from other type. dtype: {} What it means
AnyValue::as_datetime accepts only Int64 (the physical datetime representation) and Null; all other variants panic naming the dtype. Triggered when datetime conversion is attempted on e.g. a String or Float64 AnyValue instead of the Int64 physical form.
Source
Thrown at crates/polars-core/src/datatypes/any_value.rs:962
}
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,
tu: TimeUnit,
tz: Option<Arc<TimeZone>>,
) -> AnyValue<'static> {
match self {
AnyValue::Int64(v) => AnyValue::DatetimeOwned(*v, tu, tz),
AnyValue::Null => AnyValue::Null,
av => panic!(
"cannot create datetime from other type. dtype: {}",
av.dtype()View on GitHub (pinned to 68506541d2)
Solutions
- Construct Datetime AnyValues only from compatible integer timestamp values with a time unit.
- Cast the source to Int64 and supply the correct TimeUnit.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: This panic/expect fires when execution reaches an unguarded state described by: "cannot create datetime 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 datetime 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/713134f41f4e2713.
Report an issue: GitHub.