pola-rs/polars · error
Invalid Offset format (must be [-]00:00) or timezones…
Error message
Invalid Offset format (must be [-]00:00) or timezones feature not active
What it means
With the 'timezones' feature disabled, timestamp_tz_serializer has no fallback for any timezone string other than a fixed '[-]HH:MM' offset and panics with this message. It signals either a malformed offset string or a build lacking timezone support.
Solutions
- Enable the timezones feature: polars = { features = ["timezones"], ... }.
- Use strict fixed-offset format '[-]HH:MM' (e.g. '+02:00', not '+0200' or 'UTC+2') if the feature stays off.
- Drop the timezone (cast to naive/UTC timestamp) before JSON serialization.
- Align feature flags across dev/CI/production builds to avoid environment-dependent failures.
Example fix
// before
polars = { version = "0.46", features = ["json"] }
// after
polars = { version = "0.46", features = ["json", "timezones"] } Defensive patterns
Strategy: validation
Validate before calling
let timezones_enabled = cfg!(feature = "polars/timezones");
if !timezones_enabled {
assert!(tz.len() == 6 && (tz.starts_with('+') || tz.starts_with('-')),
"without 'timezones' feature only [-]HH:MM offsets are accepted, got {tz}");
} Type guard
fn is_fixed_offset(tz: &str) -> bool {
let b = tz.as_bytes();
tz.len() == 6 && (b[0] == b'+' || b[0] == b'-') && tz[1..].chars().all(|c| c.is_ascii_digit() || c == ':')
} Try / catch
// panic arm without the feature; normalize before serializing
let safe_tz = if cfg!(feature = "polars/timezones") { tz } else { to_fixed_offset(tz).unwrap_or("+00:00") }; Prevention
- Enable the 'timezones' feature in any build that writes timestamp columns with IANA zones
- Without the feature, restrict columns to strict [-]HH:MM offsets
- Cast to naive/UTC timestamps before JSON export in minimal builds
- Keep feature parity between environments to avoid env-dependent panics
When it happens
Trigger: Serializing a Timestamp array whose timezone is not a parseable fixed offset like '+02:00'/'-05:30' while polars is compiled without feature = "timezones" — e.g. writing JSON for a column with tz 'Europe/Paris' on a non-timezones build.
Common situations: Minimal polars feature sets (no 'timezones') handling data produced with IANA timezones; typos in offset strings like '+0200' or 'UTC+2'; env differences where local dev build has timezones but production build does not.
Related errors
- Timezone is invalid or not supported
- activate 'timezones' feature
- failed to serialize schema hashes file
- failed to serialize the schema
- timezone " " cannot be parsed (feature chrono-tz is not…
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/3a3af21d21a2c166.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-json/src/json/write/serialize.rs:481
Ok(parsed_tz) => {
let f = move |x: Option<&i64>, buf: &mut Vec<u8>| {
if let Some(x) = x {
let dt_str = timestamp_to_datetime(*x, time_unit, &parsed_tz).to_rfc3339();
write!(buf, "\"{dt_str}\"").unwrap();
} else {
buf.extend_from_slice(b"null")
}
};
materialize_serializer(f, array.iter(), offset, take)
},
_ => {
panic!("Timezone {tz} is invalid or not supported");
},
},
#[cfg(not(feature = "timezones"))]
_ => {
panic!("Invalid Offset format (must be [-]00:00) or timezones feature not active");
},
}
}
pub fn new_serializer<'a>(
array: &'a dyn Array,
offset: usize,
take: usize,
) -> Box<dyn JsonSerializer<Item = [u8]> + 'a + Send + Sync> {
match array.dtype().to_storage() {
ArrowDataType::Boolean => {
boolean_serializer(array.as_any().downcast_ref().unwrap(), offset, take)
},
ArrowDataType::Int8 => {
primitive_serializer::<i8>(array.as_any().downcast_ref().unwrap(), offset, take)
},
ArrowDataType::Int16 => {
primitive_serializer::<i16>(array.as_any().downcast_ref().unwrap(), offset, take)View on GitHub (pinned to fe841f959e)