{"record":{"id":"d24cc4f2336524c1","repo":"pola-rs/polars","slug":"cannot-create-duration-from-other-type-dtype","errorCode":null,"errorMessage":"cannot create duration from other type. dtype: {}","messagePattern":"cannot create duration from other type\\. dtype: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/datatypes/any_value.rs","lineNumber":990,"sourceCode":"        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()\n            ),\n        }\n    }\n\n    #[cfg(feature = \"dtype-duration\")]\n    pub(crate) fn as_duration(&self, tu: TimeUnit) -> AnyValue<'static> {\n        match self {\n            AnyValue::Int64(v) => AnyValue::Duration(*v, tu),\n            AnyValue::Null => AnyValue::Null,\n            av => panic!(\n                \"cannot create duration from other type. dtype: {}\",\n                av.dtype()\n            ),\n        }\n    }\n\n    #[cfg(feature = \"dtype-time\")]\n    pub(crate) fn as_time(&self) -> AnyValue<'static> {\n        match self {\n            AnyValue::Int64(v) => AnyValue::Time(*v),\n            AnyValue::Null => AnyValue::Null,\n            av => panic!(\"cannot create time from other type. dtype: {}\", av.dtype()),\n        }\n    }\n\n    pub(crate) fn to_i128(&self) -> Option<i128> {\n        match self {\n            AnyValue::UInt8(v) => Some((*v).into()),","sourceCodeStart":972,"sourceCodeEnd":1008,"githubUrl":"https://github.com/pola-rs/polars/blob/68506541d2de983056c9eb244e1ea05fab377dfc/crates/polars-core/src/datatypes/any_value.rs#L972-L1008","documentation":"AnyValue::as_duration converts only Int64 physical values (and Null) to a Duration value; other dtypes panic naming the dtype. Means a duration reinterpretation was requested from a value that isn't the Int64 physical duration — cast the column to Duration instead.","triggerScenarios":"This panic/expect fires when execution reaches an unguarded state described by: \"cannot create duration 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 duration 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 Duration AnyValues only from Int64 values plus a TimeUnit.","Cast the source value to Int64 in the desired time unit first."],"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"}