pola-rs/polars · error
cannot create time from other type. dtype: {}
Error message
cannot create time from other type. dtype: {} What it means
AnyValue::as_time reinterprets only Int64 (physical time-of-day) and Null; any other variant panics with this message naming the dtype. Fires when time conversion is requested from a non-Int64 AnyValue.
Source
Thrown at crates/polars-core/src/datatypes/any_value.rs:1002
#[cfg(feature = "dtype-duration")]
pub(crate) fn as_duration(&self, tu: TimeUnit) -> AnyValue<'static> {
match self {
AnyValue::Int64(v) => AnyValue::Duration(*v, tu),
AnyValue::Null => AnyValue::Null,
av => panic!(
"cannot create duration from other type. dtype: {}",
av.dtype()
),
}
}
#[cfg(feature = "dtype-time")]
pub(crate) fn as_time(&self) -> AnyValue<'static> {
match self {
AnyValue::Int64(v) => AnyValue::Time(*v),
AnyValue::Null => AnyValue::Null,
av => panic!("cannot create time from other type. dtype: {}", av.dtype()),
}
}
pub(crate) fn to_i128(&self) -> Option<i128> {
match self {
AnyValue::UInt8(v) => Some((*v).into()),
AnyValue::UInt16(v) => Some((*v).into()),
AnyValue::UInt32(v) => Some((*v).into()),
AnyValue::UInt64(v) => Some((*v).into()),
AnyValue::Int8(v) => Some((*v).into()),
AnyValue::Int16(v) => Some((*v).into()),
AnyValue::Int32(v) => Some((*v).into()),
AnyValue::Int64(v) => Some((*v).into()),
AnyValue::Int128(v) => Some(*v),
_ => None,
}
}
View on GitHub (pinned to 68506541d2)
Solutions
- Construct Time AnyValues only from Int64 nanoseconds-since-midnight.
- Convert the source value to the time representation before creating the AnyValue.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: This panic/expect fires when execution reaches an unguarded state described by: "cannot create time 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 time 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/fb250b56c1a2b17d.
Report an issue: GitHub.