pola-rs/polars · error

activate 'timezones' feature

Error message

activate 'timezones' feature

What it means

Displaying a timezone-aware Datetime value requires the 'timezones' feature of polars-core. Without that feature compiled in, the Debug/Display impl for tz-aware datetimes deliberately panics with this message instead of printing wrong output. It is a compile-time feature gate enforced at runtime in the formatting path.

Solutions

  1. Enable the feature: `polars = { version = "...", features = ["timezones"] }` in Cargo.toml.
  2. If you don't need tz-aware data, cast the column to a timezone-naive Datetime before formatting.
  3. Use `fmt = "lazy"` / avoid Display on the column until the feature is enabled.

Example fix

// before (Cargo.toml)
polars-core = { version = "0.41", default-features = false }

// after
polars-core = { version = "0.41", default-features = false, features = ["timezones", "dtype-datetime"] }
Defensive patterns

Strategy: fallback

Validate before calling

// build-time: ensure the feature
// cargo build fails otherwise; runtime guard:
let is_tz_aware = matches!(dtype, DataType::Datetime(_, Some(_)));

Type guard

fn is_tz_aware_datetime(s: &Series) -> bool {
    matches!(s.dtype(), DataType::Datetime(_, Some(_)))
}

Try / catch

// Rust panics are not catchable here; guard before formatting:
if is_tz_aware_datetime(&s) && !cfg!(feature = "timezones") {
    let s_naive = s.cast(&DataType::Datetime(TimeUnit::Microseconds, None))?;
    println!("{}", s_naive);
} else {
    println!("{}", s);
}

Prevention

When it happens

Trigger: Printing or `println!`-ing a DataFrame/Series containing a Datetime column with a time zone (e.g. dtype Datetime(tu, "UTC") or "Asia/Kathmandu") while polars-core was built without the `timezones` feature.

Common situations: Cargo dependency declared as `polars = { version = "...", default-features = false }` and the user later writes tz-aware data; a workspace tightening features for binary size dropping `timezones`; tutorial code that assumes full features.

Related errors


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

Appendix: source

Thrown at crates/polars-core/src/fmt.rs:1269

    }
}

#[cfg(feature = "dtype-datetime")]
impl Display for PlTzAware<'_> {
    #[allow(unused_variables)]
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        #[cfg(feature = "timezones")]
        match self.tz.parse::<chrono_tz::Tz>() {
            Ok(tz) => {
                let dt_utc = chrono::Utc.from_local_datetime(&self.ndt).unwrap();
                let dt_tz_aware = dt_utc.with_timezone(&tz);
                write!(f, "{dt_tz_aware}")
            },
            Err(_) => write!(f, "invalid timezone"),
        }
        #[cfg(not(feature = "timezones"))]
        {
            panic!("activate 'timezones' feature")
        }
    }
}

/// Renders a map row as `{"a": 1, "b": 2}`
#[cfg(feature = "dtype-map")]
fn fmt_map(f: &mut Formatter<'_>, entries: &Series) -> fmt::Result {
    let (keys, values) =
        try_unpack_map_entries(entries).expect("Map entries have canonical key and value fields");

    // Same truncation as `Series::fmt_list`.
    let max_items = get_list_len_limit();
    let ellipsis = get_ellipsis();
    let shown = max_items.min(entries.len());

    write!(f, "{{")?;
    for i in 0..shown {
        if i > 0 {

View on GitHub (pinned to fe841f959e)