{"record":{"id":"af035c4dc21f80c3","repo":"pola-rs/polars","slug":"out-of-range-duration","errorCode":null,"errorMessage":"out-of-range duration","messagePattern":"out-of-range duration","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-arrow/src/temporal_conversions.rs","lineNumber":79,"sourceCode":"        .expect(\"invalid or out-of-range datetime\")\n}\n\n/// converts a `i64` representing a `date64` to [`NaiveDate`]\n#[inline]\npub fn date64_to_date(milliseconds: i64) -> NaiveDate {\n    date64_to_datetime(milliseconds).date()\n}\n\n/// converts a `i32` representing a `time32(s)` to [`NaiveTime`]\n#[inline]\npub fn time32s_to_time(v: i32) -> NaiveTime {\n    NaiveTime::from_num_seconds_from_midnight_opt(v as u32, 0).expect(\"invalid time\")\n}\n\n/// converts a `i64` representing a `duration(s)` to [`Duration`]\n#[inline]\npub fn duration_s_to_duration(v: i64) -> Duration {\n    Duration::try_seconds(v).expect(\"out-of-range duration\")\n}\n\n/// converts a `i64` representing a `duration(ms)` to [`Duration`]\n#[inline]\npub fn duration_ms_to_duration(v: i64) -> Duration {\n    Duration::try_milliseconds(v).expect(\"out-of-range in duration conversion\")\n}\n\n/// converts a `i64` representing a `duration(us)` to [`Duration`]\n#[inline]\npub fn duration_us_to_duration(v: i64) -> Duration {\n    Duration::microseconds(v)\n}\n\n/// converts a `i64` representing a `duration(ns)` to [`Duration`]\n#[inline]\npub fn duration_ns_to_duration(v: i64) -> Duration {\n    Duration::nanoseconds(v)","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-arrow/src/temporal_conversions.rs#L61-L97","documentation":"`duration_s_to_duration` converts an i64 seconds value into a chrono `Duration` via `Duration::try_seconds`. When the value exceeds what chrono's Duration can represent (out of ±i64-millisecond-ish span, roughly ±292 years), `try_seconds` returns `None` and `.expect(\"out-of-range duration\")` panics.","triggerScenarios":"Calling `duration_s_to_duration(v)` with |v| beyond chrono Duration's representable range (about ±9.2e15 seconds is safe; near i64::MAX seconds overflows).","commonSituations":"Sentinel values (i64::MAX) in duration(s) columns; unit confusion treating a nanosecond field as seconds; extreme test data.","solutions":["Check the value against chrono's Duration limits before conversion, or use `chrono::Duration::try_seconds(v)` directly and handle `None`.","Replace sentinel/garbage values in the column before conversion.","Confirm the unit is actually seconds, not ms/us/ns, which would scale the value out of range."],"exampleFix":"// before\nlet d = duration_s_to_duration(v); // panics on i64::MAX\n// after\nlet d = chrono::Duration::try_seconds(v)\n    .ok_or_else(|| anyhow!(\"duration seconds {v} out of range\"))?;","handlingStrategy":"validation","validationCode":"fn duration_s_in_range(v: i64) -> bool {\n    chrono::Duration::try_seconds(v).is_some()\n}","typeGuard":null,"tryCatchPattern":"match chrono::Duration::try_seconds(v) {\n    Some(d) => /* use d */,\n    None => /* handle out-of-range duration */,\n}","preventionTips":["Screen for sentinel values like i64::MAX in duration columns","Confirm the column unit is seconds before conversion","Cap aggregate durations before storing them in duration(s) arrays"],"tags":["arrow","chrono","duration","out-of-range"],"backgroundTag":"value-out-of-range","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"}