{"record":{"id":"8c7460347ecb3872","repo":"pola-rs/polars","slug":"into-duration-not-implemented-for-dt","errorCode":null,"errorMessage":"into_duration not implemented for {dt:?}","messagePattern":"into_duration not implemented for (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/series/mod.rs","lineNumber":1022,"sourceCode":"        {\n            panic!(\"activate feature dtype-duration\")\n        }\n        #[cfg(feature = \"dtype-duration\")]\n        match self.dtype() {\n            DataType::Int64 => self\n                .i64()\n                .unwrap()\n                .clone()\n                .into_duration(timeunit)\n                .into_series(),\n            DataType::Duration(_) => self\n                .duration()\n                .unwrap()\n                .physical()\n                .clone()\n                .into_duration(timeunit)\n                .into_series(),\n            dt => panic!(\"into_duration not implemented for {dt:?}\"),\n        }\n    }\n\n    // used for formatting\n    pub fn str_value(&self, index: usize) -> PolarsResult<Cow<'_, str>> {\n        Ok(self.0.get(index)?.str_value())\n    }\n    /// Get the head of the Series.\n    pub fn head(&self, length: Option<usize>) -> Series {\n        let len = length.unwrap_or(HEAD_DEFAULT_LENGTH);\n        self.slice(0, std::cmp::min(len, self.len()))\n    }\n\n    /// Get the tail of the Series.\n    pub fn tail(&self, length: Option<usize>) -> Series {\n        let len = length.unwrap_or(TAIL_DEFAULT_LENGTH);\n        let len = std::cmp::min(len, self.len());\n        self.slice(-(len as i64), len)","sourceCodeStart":1004,"sourceCodeEnd":1040,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/series/mod.rs#L1004-L1040","documentation":"Series::into_duration only implements the conversion for Int64-backed data (the physical representation of Duration). Any other input dtype reaches a catch-all `dt =>` arm that panics. The `dtype-duration` feature is on (otherwise error 140 fires instead), but the source series dtype is not convertible.","triggerScenarios":"Calling into_duration on a Series whose dtype is not Int64 — e.g. a UInt64, Float64, or Datetime column — typically through a cast to Duration performed by finish_cast.","commonSituations":"Reading data whose column was inferred as Float or Date and then casting to Duration; converting epoch values stored as floats; schema mismatches after a parquet/CSV read where the column is not Int64.","solutions":["Cast the column to Int64 first: series.cast(&DataType::Int64)?.into_duration(timeunit)","If the column is a Date/Datetime and you want a duration, compute the difference explicitly (e.g. subtracting a baseline) rather than casting directly","Check the source schema (parquet/CSV dtypes) and force Int64 at read time via schema overrides","If the values are floats representing durations, round/truncate to Int64 before conversion"],"exampleFix":"// before\nlet dur = s.into_duration(TimeUnit::Nanoseconds);\n// after\nlet dur = s.cast(&DataType::Int64)?.into_duration(TimeUnit::Nanoseconds);","handlingStrategy":"validation","validationCode":"fn can_into_duration(s: &polars::prelude::Series) -> bool {\n    matches!(s.dtype(), polars::prelude::DataType::Int64)\n}\nif !can_into_duration(&s) { s.cast(&DataType::Int64)?; }","typeGuard":"fn is_i64_series(s: &Series) -> bool { matches!(s.dtype(), DataType::Int64) }","tryCatchPattern":null,"preventionTips":["Cast to Int64 before converting to Duration","Override CSV/parquet schemas at read time so duration-source columns are Int64","Never cast Date/Datetime directly to Duration; compute differences instead"],"tags":["rust","polars","dtype","cast"],"backgroundTag":"unsupported-dtype","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}