{"record":{"id":"6e7ac40bde47ec01","repo":"pola-rs/polars","slug":"activate-timezones-feature-6e7ac4","errorCode":null,"errorMessage":"activate 'timezones' feature","messagePattern":"activate 'timezones' feature","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-io/src/csv/write/write_impl/serializer.rs","lineNumber":817,"sourceCode":"        )?,\n        #[cfg(feature = \"dtype-datetime\")]\n        DataType::Datetime(time_unit, _) => {\n            let format = chrono::format::StrftimeItems::new(_datetime_format)\n                .parse()\n                .map_err(|_| {\n                    polars_err!(\n                        ComputeError: \"cannot format {} with format '{_datetime_format}'\",\n                        if _time_zone.is_some() { \"DateTime\" } else { \"NaiveDateTime\" },\n                    )\n                })?;\n            use std::fmt::Write;\n            let sample_datetime = match _time_zone {\n                #[cfg(feature = \"timezones\")]\n                Some(time_zone) => time_zone\n                    .from_utc_datetime(&chrono::NaiveDateTime::MAX)\n                    .format_with_items(format.iter()),\n                #[cfg(not(feature = \"timezones\"))]\n                Some(_) => panic!(\"activate 'timezones' feature\"),\n                None => chrono::NaiveDateTime::MAX.format_with_items(format.iter()),\n            };\n            // Fail fast for invalid format. This return error faster to the user, and allows us to not return\n            // `Result` from `serialize()`.\n            write!(IgnoreFmt, \"{sample_datetime}\").map_err(|_| {\n                polars_err!(\n                    ComputeError: \"cannot format {} with format '{_datetime_format}'\",\n                    if _time_zone.is_some() { \"DateTime\" } else { \"NaiveDateTime\" },\n                )\n            })?;\n\n            let array = array.as_any().downcast_ref().unwrap();\n\n            macro_rules! time_unit_serializer {\n                ($convert:ident) => {\n                    match _time_zone {\n                        #[cfg(feature = \"timezones\")]\n                        Some(time_zone) => {","sourceCodeStart":799,"sourceCodeEnd":835,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/crates/polars-io/src/csv/write/write_impl/serializer.rs#L799-L835","documentation":"While initializing the CSV serializer for Datetime columns, polars formats a sample timestamp to fail fast on bad format strings. Localizing that sample to a time zone requires chrono-tz, which is only present with the timezones cargo feature; without it, the cfg(not(feature = \"timezones\")) arm panics as soon as a tz-aware Datetime column is written, even if the format string is fine.","triggerScenarios":"df.write_csv() (or CsvWriter) over a DataFrame containing DataType::Datetime(_, Some(tz)) - with or without a custom date_format - in a build where the timezones feature is off.","commonSituations":"Reading tz-aware parquet/IPC and dumping to CSV in a trimmed Rust build; code that worked in python-polars (features always on) failing after a port; feature drift after a dependency upgrade.","solutions":["Enable the timezones feature on your polars dependency (features = [\"timezones\"])","Or strip the zone before writing: df.with_column(col(\"ts\").dt().replace_time_zone(None))","Or write Parquet/NDJSON instead - they do not go through this strftime path"],"exampleFix":"// before (panics in a build without the `timezones` feature)\nlet bytes = df.clone().write_csv()?;\n\n// after (choose one)\n// 1) Cargo.toml: polars = { version = \"...\", features = [\"timezones\"] }\n// 2) drop the tz first:\nlet df = df.with_column(col(\"ts\").dt().replace_time_zone(None).alias(\"ts\"))?;\nlet bytes = df.write_csv()?;","handlingStrategy":"fallback","validationCode":"fn has_tz_aware_datetime(df: &DataFrame) -> bool {\n    df.schema().iter_values().any(|dt| matches!(dt, DataType::Datetime(_, Some(_))))\n}\n// if true and your build lacks the `timezones` feature, strip zones before writing:\n// df.apply(\"ts\", |s| s.datetime().map(|ca| ca.replace_time_zone(None).into_series()))?;","typeGuard":null,"tryCatchPattern":"catch_unwind(AssertUnwindSafe(|| df.write_csv(...))) only converts the panic to an error message; prefer the schema pre-check + replace_time_zone(None) fallback so the write never enters the failing branch.","preventionTips":["Unit-test writing a one-row tz-aware frame so the feature gap fails in CI","Centralize polars features in one company-wide feature set","Choose Parquet/NDJSON for interchange when build size forbids timezones"],"tags":["polars","csv","datetime","timezone","cargo-features","serialization","panic"],"backgroundTag":"missing-cargo-feature","analyzedSha":"9b5d73fd00236295624374b075d16b1fe6ec6df9","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}