pola-rs/polars · error

activate feature dtype-duration

Error message

activate feature dtype-duration

What it means

This panic comes from Series::into_duration, a compile-time-gated API. Polars' Duration dtype is only compiled in when the `dtype-duration` cargo feature is enabled; without it, the function body is replaced by an unconditional panic. It means you called into_duration (directly or via a cast to Duration) on a build that cannot represent Duration.

Solutions

  1. Enable the feature in Cargo.toml: polars = { version = "...", features = ["dtype-duration"] }
  2. If you do not actually need Duration, cast to a supported dtype (e.g. keep Int64 or cast to Datetime) instead
  3. Run `cargo tree -e features` / check `cargo features` to confirm `dtype-duration` is actually enabled in the unified feature graph (another crate may be disabling default features)
  4. Check that you are not using a polars fork/pinned version where the feature name differs

Example fix

// before
polars = { version = "0.46", features = ["lazy"] }
// after
polars = { version = "0.46", features = ["lazy", "dtype-duration"] }
Defensive patterns

Strategy: validation

Validate before calling

fn dtype_duration_supported() -> bool {
    // compile-time probe; swap for your own cfg when building on polars
    cfg!(feature = "dtype-duration")
}
if !dtype_duration_supported() {
    eprintln!("casting to Duration requires the polars 'dtype-duration' feature");
}

Prevention

When it happens

Trigger: Calling Series::into_duration (e.g. via DataFrame::cast / finish_cast to DataType::Duration) on a polars-core build without the `dtype-duration` feature.

Common situations: Users add polars as a dependency with default features or a reduced feature set, then a downstream API (casting an Int64/other column to Duration, e.g. parsing timestamps) hits the disabled code path; also happens after upgrading polars where features were renamed or pruned.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/c538dab15cf4075d. Report an issue: GitHub.

Appendix: source

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

                .clone()
                .into_datetime(timeunit, tz)
                .into_series(),
            DataType::Datetime(_, _) => self
                .datetime()
                .unwrap()
                .physical()
                .clone()
                .into_datetime(timeunit, tz)
                .into_series(),
            dt => panic!("into_datetime not implemented for {dt:?}"),
        }
    }

    #[allow(unused_variables)]
    pub fn into_duration(self, timeunit: TimeUnit) -> Series {
        #[cfg(not(feature = "dtype-duration"))]
        {
            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:?}"),
        }

View on GitHub (pinned to fe841f959e)