pola-rs/polars · error
activate 'timezones' feature
Error message
activate 'timezones' feature
What it means
When parsing a string ChunkedArray into a Datetime, if the inferred format indicates a timezone offset the code paths under cfg(feature = "timezones") construct a timezone-aware Datetime; with the feature compiled out, the library explicitly panics to say timezone support is missing.
Solutions
- Enable the 'timezones' feature in Cargo.toml: polars = { version = "...", features = ["timezones", "temporal"] }.
- Strip the timezone suffix from strings before parsing and parse as naive Datetime.
- Parse as Datetime with an explicit format that excludes the offset, or cast to Date instead.
- If offsets must be honored, upgrade to a build with 'timezones' (default feature of the full polars meta-crate).
Example fix
// before
polars = { version = "0.40", default-features = false, features = ["lazy", "temporal"] }
// after
polars = { version = "0.40", default-features = false, features = ["lazy", "temporal", "timezones"] } Defensive patterns
Strategy: fallback
Validate before calling
// detect tz offsets in the strings you will parse
let has_tz = string_series.str()?.contains("(Z|[+-]\d{2}:?\d{2})$")?;
if has_tz && !cfg!(feature = "timezones") { /* strip offsets or enable feature */ } Prevention
- Compile polars with the 'timezones' feature when data contains tz-aware timestamps
- Strip 'Z'/+hh:mm suffixes before parsing if tz support is not compiled in
- Use str.to_datetime with an explicit offset-free format
When it happens
Trigger: Calling str.to_datetime(...) / cast from String to Datetime on strings containing a timezone offset (e.g. '2024-01-01T00:00:00+02:00') while polars was built without the 'timezones' feature.
Common situations: Using the default polars crate features (or the slim polars-core) when your data includes ISO timestamps with 'Z' or '+hh:mm' offsets; CI images built with a reduced feature set.
Related errors
- activate 'timezones' feature
- expected index type found
- activate 'decompress' feature
- activate dtype
- activate dtype-categorical to convert dictionary arrays
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/cc2b25de07ad9d51.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-core/src/chunked_array/temporal/string/mod.rs:291
if tz_aware {
#[cfg(feature = "timezones")]
{
let mut convert = LruCachedFunc::new(
|s: &str| {
let dt = DateTime::parse_from_str(s, &fmt).ok()?;
Some(func(dt.naive_utc()))
},
(string_ca.len() as f64).sqrt() as usize,
);
Ok(
unary_elementwise(string_ca, |opt_s| convert.eval(opt_s?, use_cache))
.with_name(string_ca.name().clone())
.into_datetime(tu, Some(tz.cloned().unwrap_or(TimeZone::UTC))),
)
}
#[cfg(not(feature = "timezones"))]
{
panic!("activate 'timezones' feature")
}
} else {
let transform = match tu {
TimeUnit::Nanoseconds => infer::transform_datetime_ns,
TimeUnit::Microseconds => infer::transform_datetime_us,
TimeUnit::Milliseconds => infer::transform_datetime_ms,
};
let ca = if strptime::fast_parser_supported(fmt.as_bytes()) {
let mut strptime_cache = StrpTimeState::default();
let mut convert = LruCachedFunc::new(
|s: &str| match strptime_cache.parse(s.as_bytes(), fmt.as_bytes()) {
None => transform(s, &fmt),
Some(ndt) => Some(func(ndt)),
},
(string_ca.len() as f64).sqrt() as usize,
);
unary_elementwise(string_ca, |opt_s| convert.eval(opt_s?, use_cache))
} else {View on GitHub (pinned to fe841f959e)