{"record":{"id":"dffd3672a15787d9","repo":"pola-rs/polars","slug":"not-implemented-dffd36","errorCode":null,"errorMessage":"not implemented","messagePattern":"not implemented","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-arrow/src/compute/temporal.rs","lineNumber":72,"sourceCode":"    ($extract:ident, $array:ident, $dtype:path) => {\n        match $array.dtype().to_storage() {\n            ArrowDataType::Date32 | ArrowDataType::Date64 | ArrowDataType::Timestamp(_, None) => {\n                date_variants($array, $dtype, |x| x.$extract().try_into().unwrap())\n            },\n            ArrowDataType::Timestamp(time_unit, Some(timezone_str)) => {\n                let array = $array.as_any().downcast_ref().unwrap();\n\n                if let Ok(timezone) = parse_offset(timezone_str.as_str()) {\n                    Ok(extract_impl(array, *time_unit, timezone, |x| {\n                        x.$extract().try_into().unwrap()\n                    }))\n                } else {\n                    chrono_tz(array, *time_unit, timezone_str.as_str(), |x| {\n                        x.$extract().try_into().unwrap()\n                    })\n                }\n            },\n            _ => unimplemented!(),\n        }\n    };\n}\n\n/// Extracts the years of a temporal array as [`PrimitiveArray<i32>`].\npub fn year(array: &dyn Array) -> PolarsResult<PrimitiveArray<i32>> {\n    date_like!(year, array, ArrowDataType::Int32)\n}\n\n/// Extracts the months of a temporal array as [`PrimitiveArray<i8>`].\n///\n/// Value ranges from 1 to 12.\npub fn month(array: &dyn Array) -> PolarsResult<PrimitiveArray<i8>> {\n    date_like!(month, array, ArrowDataType::Int8)\n}\n\n/// Extracts the days of a temporal array as [`PrimitiveArray<i8>`].\n///","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/crates/polars-arrow/src/compute/temporal.rs#L54-L90","documentation":"The date_like! macro backs year/month/day/weekday/iso_week in polars-arrow::compute::temporal. It only accepts Date32, Date64 and Timestamp (naive or zoned); every other dtype falls into _ => unimplemented!() (crates/polars-arrow/src/compute/temporal.rs:72) and panics, even though the public functions return PolarsResult. The doc comments advertise can_* predicates, but this file defines none, so callers must check dtypes themselves.","triggerScenarios":"Calling year/month/day/weekday/iso_week on Time32/Time64/Duration arrays, or on plain Int32/Int64 arrays holding epoch values that were never cast to a date dtype.","commonSituations":"Parquet or CSV columns inferred as Int64 that the user assumes are dates; timestamps loaded through a path that drops the logical type; subtracting two dates into a Duration and then extracting year(); pl.time columns passed to date extractors.","solutions":["Cast to a true temporal dtype first, e.g. cast(&arr, &ArrowDataType::Timestamp(TimeUnit::Microsecond, None)) or Date32","If values are epoch integers, convert via the epoch helpers instead of calling year() on primitives","Guard with a matches! on array.dtype().to_storage() before calling","For time-of-day dtypes use hour/minute/second (time_like) which accept Time32/Time64"],"exampleFix":"// before\nlet years = temporal::year(&int64_array)?; // panics: _ => unimplemented!()\n\n// after\nlet dates = cast(&int64_array, &ArrowDataType::Timestamp(TimeUnit::Microsecond, None))?;\nlet years = temporal::year(dates.as_ref())?;","handlingStrategy":"type-guard","validationCode":"if !can_extract_date(array.dtype()) {\n    polars_bail!(InvalidOperation: \"date extraction requires Date32/Date64/Timestamp, got {:?}\", array.dtype());\n}","typeGuard":"fn can_extract_date(dtype: &ArrowDataType) -> bool {\n    matches!(\n        dtype.to_storage(),\n        ArrowDataType::Date32 | ArrowDataType::Date64 | ArrowDataType::Timestamp(_, _)\n    )\n}","tryCatchPattern":"let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| temporal::year(array)));\nlet years = match res {\n    Ok(v) => v?,\n    Err(_) => polars_bail!(InvalidOperation: \"year() panicked: cast {:?} to Date/Timestamp first\", array.dtype()),\n};","preventionTips":["Always cast epoch columns to Timestamp/Date at ingestion; never rely on physical layout","Centralize dtype validation before temporal kernels","Unit-test temporal extraction against every dtype your pipeline can see"],"tags":["rust","polars-arrow","temporal","date","dtype","panic"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}