pola-rs/polars · error

into_duration not implemented for {dt:?}

Error message

into_duration not implemented for {dt:?}

What it means

Series::into_duration (feature enabled) converts only Int64 physical values and Duration series; other dtypes fall through to this panic naming the dtype. Cast the series to Int64 (the physical duration representation) before calling into_duration.

Source

Thrown at crates/polars-core/src/series/mod.rs:1009

        {
            panic!("activate feature dtype-duration")
        }
        #[cfg(feature = "dtype-duration")]
        match self.dtype() {
            DataType::Int64 => self
                .i64()
                .unwrap()
                .clone()
                .into_duration(timeunit)
                .into_series(),
            DataType::Duration(_) => self
                .duration()
                .unwrap()
                .physical()
                .clone()
                .into_duration(timeunit)
                .into_series(),
            dt => panic!("into_duration not implemented for {dt:?}"),
        }
    }

    // used for formatting
    pub fn str_value(&self, index: usize) -> PolarsResult<Cow<'_, str>> {
        Ok(self.0.get(index)?.str_value())
    }
    /// Get the head of the Series.
    pub fn head(&self, length: Option<usize>) -> Series {
        let len = length.unwrap_or(HEAD_DEFAULT_LENGTH);
        self.slice(0, std::cmp::min(len, self.len()))
    }

    /// Get the tail of the Series.
    pub fn tail(&self, length: Option<usize>) -> Series {
        let len = length.unwrap_or(TAIL_DEFAULT_LENGTH);
        let len = std::cmp::min(len, self.len());
        self.slice(-(len as i64), len)

View on GitHub (pinned to 68506541d2)

Solutions

  1. Convert to Duration only from supported dtypes (Datetime differences, Int64).
  2. Cast the source to Int64 with the desired time unit first.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: This panic/expect fires when execution reaches an unguarded state described by: "into_duration not implemented for {dt:?}". 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 ("into_duration not implemented for {dt:?}"). 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/8c7460347ecb3872. Report an issue: GitHub.