{"record":{"id":"524a152d9eb3e719","repo":"pola-rs/polars","slug":"invalid-call-to-get-strftime-format-fmt-fmt-dtype-dtype","errorCode":null,"errorMessage":"invalid call to `get_strftime_format`; fmt={fmt:?}, dtype={dtype}","messagePattern":"invalid call to `get_strftime_format`; fmt=(.+?), dtype=(.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/chunked_array/temporal/conversion.rs","lineNumber":83,"sourceCode":"            match dtype {\n                #[cfg(feature = \"dtype-datetime\")]\n                DataType::Datetime(tu, tz) => match (tu, tz.is_some()) {\n                    (TimeUnit::Milliseconds, true) => format!(\"%F{sep}%T%.3f%:z\"),\n                    (TimeUnit::Milliseconds, false) => format!(\"%F{sep}%T%.3f\"),\n                    (TimeUnit::Microseconds, true) => format!(\"%F{sep}%T%.6f%:z\"),\n                    (TimeUnit::Microseconds, false) => format!(\"%F{sep}%T%.6f\"),\n                    (TimeUnit::Nanoseconds, true) => format!(\"%F{sep}%T%.9f%:z\"),\n                    (TimeUnit::Nanoseconds, false) => format!(\"%F{sep}%T%.9f\"),\n                },\n                #[cfg(feature = \"dtype-date\")]\n                DataType::Date => \"%F\".to_string(),\n                #[cfg(feature = \"dtype-time\")]\n                DataType::Time => \"%T%.f\".to_string(),\n                _ => {\n                    let err = format!(\n                        \"invalid call to `get_strftime_format`; fmt={fmt:?}, dtype={dtype}\"\n                    );\n                    unimplemented!(\"{}\", err)\n                },\n            }\n        };\n        Ok(format_string)\n    }\n}\n","sourceCodeStart":65,"sourceCodeEnd":90,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/chunked_array/temporal/conversion.rs#L65-L90","documentation":"get_strftime_format maps a temporal DataType plus optional format to a strftime format string and only implements the known temporal dtype/format combinations (Date, Datetime with/without tz, Time). Any other pairing hits an unimplemented!() guard. It is an internal assertion that the dtype being stringified is a supported temporal one.","triggerScenarios":"Calling to_string()/cast to String on a ChunkedArray whose dtype is not Date, Datetime, or Time (e.g. Int64 timestamps), or invoking get_strftime_format directly with an invalid (fmt, dtype) combination.","commonSituations":"Formatting a numeric timestamp column to string without casting to Datetime first; a series that lost its logical dtype (e.g. after a raw cast or from_arrow mapping issue); plugin/custom code passing unexpected dtype.","solutions":["Cast the column to the intended temporal dtype before formatting: df.col(\"ts\")?.cast(&DataType::Datetime(TimeUnit::Microseconds, None)).","Use dt.strftime(...) expressions only on Date/Datetime/Time typed columns.","Check the series dtype with series.dtype() and handle non-temporal dtypes before calling to_string.","If you provide an explicit fmt argument, ensure the dtype is temporal so the (fmt, dtype) pair is valid."],"exampleFix":"// before\nlet s = df.column(\"ts\")?.to_string(); // ts is Int64 -> panics\n// after\nlet s = df.column(\"ts\")?\n    .cast(&DataType::Datetime(TimeUnit::Microseconds, None))?\n    .to_string();","handlingStrategy":"validation","validationCode":"if !matches!(s.dtype(), DataType::Date | DataType::Time | DataType::Datetime(..)) {\n    return Err(PolarsError::ComputeError(\"non-temporal dtype\".into()));\n}\nlet formatted = s.to_string();","typeGuard":"fn is_temporal_dtype(dt: &DataType) -> bool {\n    matches!(dt, DataType::Date | DataType::Time | DataType::Datetime(..))\n}","tryCatchPattern":"Check dtype before to_string; polars panics, so validate instead of catching:\nlet s = if is_temporal_dtype(series.dtype()) { series.to_string() } else { series.cast(&DataType::Datetime(...))?.to_string() };","preventionTips":["Verify series.dtype() is temporal before strftime/to_string formatting","Cast numeric timestamps to Datetime before string formatting","Keep dtype metadata intact (avoid raw casts that erase logical types)"],"tags":["polars","panic","temporal","strftime","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}