{"record":{"id":"713134f41f4e2713","repo":"pola-rs/polars","slug":"cannot-create-datetime-from-other-type-dtype","errorCode":null,"errorMessage":"cannot create datetime from other type. dtype: {}","messagePattern":"cannot create datetime from other type\\. dtype: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/datatypes/any_value.rs","lineNumber":962,"sourceCode":"}\n\nimpl<'a> AnyValue<'a> {\n    #[cfg(any(feature = \"dtype-date\", feature = \"dtype-datetime\"))]\n    pub(crate) fn as_date(&self) -> AnyValue<'static> {\n        match self {\n            #[cfg(feature = \"dtype-date\")]\n            AnyValue::Int32(v) => AnyValue::Date(*v),\n            AnyValue::Null => AnyValue::Null,\n            av => panic!(\"cannot create date from other type. dtype: {}\", av.dtype()),\n        }\n    }\n\n    #[cfg(feature = \"dtype-datetime\")]\n    pub(crate) fn as_datetime(&self, tu: TimeUnit, tz: Option<&'a TimeZone>) -> AnyValue<'a> {\n        match self {\n            AnyValue::Int64(v) => AnyValue::Datetime(*v, tu, tz),\n            AnyValue::Null => AnyValue::Null,\n            av => panic!(\n                \"cannot create datetime from other type. dtype: {}\",\n                av.dtype()\n            ),\n        }\n    }\n\n    #[cfg(feature = \"dtype-datetime\")]\n    pub(crate) fn as_datetime_owned(\n        &self,\n        tu: TimeUnit,\n        tz: Option<Arc<TimeZone>>,\n    ) -> AnyValue<'static> {\n        match self {\n            AnyValue::Int64(v) => AnyValue::DatetimeOwned(*v, tu, tz),\n            AnyValue::Null => AnyValue::Null,\n            av => panic!(\n                \"cannot create datetime from other type. dtype: {}\",\n                av.dtype()","sourceCodeStart":944,"sourceCodeEnd":980,"githubUrl":"https://github.com/pola-rs/polars/blob/68506541d2de983056c9eb244e1ea05fab377dfc/crates/polars-core/src/datatypes/any_value.rs#L944-L980","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Construct Datetime AnyValues only from compatible integer timestamp values with a time unit.","Cast the source to Int64 and supply the correct TimeUnit."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"68506541d2de983056c9eb244e1ea05fab377dfc","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}