{"record":{"id":"b3c090715edad2f1","repo":"pola-rs/polars","slug":"activate-timezones-feature","errorCode":null,"errorMessage":"activate 'timezones' feature","messagePattern":"activate 'timezones' feature","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/fmt.rs","lineNumber":1269,"sourceCode":"    }\n}\n\n#[cfg(feature = \"dtype-datetime\")]\nimpl Display for PlTzAware<'_> {\n    #[allow(unused_variables)]\n    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {\n        #[cfg(feature = \"timezones\")]\n        match self.tz.parse::<chrono_tz::Tz>() {\n            Ok(tz) => {\n                let dt_utc = chrono::Utc.from_local_datetime(&self.ndt).unwrap();\n                let dt_tz_aware = dt_utc.with_timezone(&tz);\n                write!(f, \"{dt_tz_aware}\")\n            },\n            Err(_) => write!(f, \"invalid timezone\"),\n        }\n        #[cfg(not(feature = \"timezones\"))]\n        {\n            panic!(\"activate 'timezones' feature\")\n        }\n    }\n}\n\n/// Renders a map row as `{\"a\": 1, \"b\": 2}`\n#[cfg(feature = \"dtype-map\")]\nfn fmt_map(f: &mut Formatter<'_>, entries: &Series) -> fmt::Result {\n    let (keys, values) =\n        try_unpack_map_entries(entries).expect(\"Map entries have canonical key and value fields\");\n\n    // Same truncation as `Series::fmt_list`.\n    let max_items = get_list_len_limit();\n    let ellipsis = get_ellipsis();\n    let shown = max_items.min(entries.len());\n\n    write!(f, \"{{\")?;\n    for i in 0..shown {\n        if i > 0 {","sourceCodeStart":1251,"sourceCodeEnd":1287,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/fmt.rs#L1251-L1287","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Enable the feature: `polars = { version = \"...\", features = [\"timezones\"] }` in Cargo.toml.","If you don't need tz-aware data, cast the column to a timezone-naive Datetime before formatting.","Use `fmt = \"lazy\"` / avoid Display on the column until the feature is enabled."],"exampleFix":"// before (Cargo.toml)\npolars-core = { version = \"0.41\", default-features = false }\n\n// after\npolars-core = { version = \"0.41\", default-features = false, features = [\"timezones\", \"dtype-datetime\"] }","handlingStrategy":"fallback","validationCode":"// build-time: ensure the feature\n// cargo build fails otherwise; runtime guard:\nlet is_tz_aware = matches!(dtype, DataType::Datetime(_, Some(_)));","typeGuard":"fn is_tz_aware_datetime(s: &Series) -> bool {\n    matches!(s.dtype(), DataType::Datetime(_, Some(_)))\n}","tryCatchPattern":"// Rust panics are not catchable here; guard before formatting:\nif is_tz_aware_datetime(&s) && !cfg!(feature = \"timezones\") {\n    let s_naive = s.cast(&DataType::Datetime(TimeUnit::Microseconds, None))?;\n    println!(\"{}\", s_naive);\n} else {\n    println!(\"{}\", s);\n}","preventionTips":["Always enable `timezones` when your data may contain tz-aware datetimes.","Cast to naive datetimes at ingestion boundaries if tz handling is not needed."],"tags":["rust","polars","feature-flag","timezones","formatting"],"backgroundTag":"feature-not-enabled","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}