{"record":{"id":"acd69bd528d08c36","repo":"pola-rs/polars","slug":"dtype-not-yet-supported-in-checked-div","errorCode":null,"errorMessage":"dtype not yet supported in checked div","messagePattern":"dtype not yet supported in checked div","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/series/arithmetic/borrowed.rs","lineNumber":345,"sourceCode":"                    .unwrap()\n                    .apply(|opt_v| {\n                        opt_v.and_then(|v| {\n                            let res = rhs.to_f32().unwrap();\n                            if res.is_zero() { None } else { Some(v / res) }\n                        })\n                    })\n                    .into_series(),\n                Float64 => s\n                    .f64()\n                    .unwrap()\n                    .apply(|opt_v| {\n                        opt_v.and_then(|v| {\n                            let res = rhs.to_f64().unwrap();\n                            if res.is_zero() { None } else { Some(v / res) }\n                        })\n                    })\n                    .into_series(),\n                _ => panic!(\"dtype not yet supported in checked div\"),\n            };\n            out.cast(self.dtype())\n        }\n    }\n}\n\npub fn coerce_lhs_rhs<'a>(\n    lhs: &'a Series,\n    rhs: &'a Series,\n) -> PolarsResult<(Cow<'a, Series>, Cow<'a, Series>)> {\n    if let Some(result) = coerce_time_units(lhs, rhs) {\n        return Ok(result);\n    }\n    let (left_dtype, right_dtype) = (lhs.dtype(), rhs.dtype());\n    let leaf_super_dtype = try_get_supertype(left_dtype.leaf_dtype(), right_dtype.leaf_dtype())?;\n\n    let mut new_left_dtype = left_dtype.cast_leaf(leaf_super_dtype.clone());\n    let mut new_right_dtype = right_dtype.cast_leaf(leaf_super_dtype);","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/series/arithmetic/borrowed.rs#L327-L363","documentation":"`Series::checked_div_num` divides a numeric Series by a scalar, but only a limited set of dtypes is implemented in its match; hitting the `_` arm panics with 'dtype not yet supported in checked div'. The result is then cast back to the original dtype, so only dtypes with a defined division path (e.g. Float64-backed arithmetic) are supported.","triggerScenarios":"Calling `series.checked_div_num(scalar)` on a Series whose dtype falls into the unimplemented match arm (e.g. certain integer/decimal/temporal dtypes); the visible caller is `test_checked_div`, but any user code invoking checked_div_num on such a dtype triggers it.","commonSituations":"Dividing integer or non-float columns by a float scalar and expecting automatic promotion; migrating code from `apply`-based division to checked_div_num without checking dtype coverage.","solutions":["Cast the Series to Float64 before calling checked_div_num, then cast back if needed.","Implement the division manually with `series.cast(DataType::Float64)?.divide(...)` or apply elementwise `floor_div`/`div` as appropriate.","For integers, consider `checked_div`-style arithmetic operators or `Series::divide` which supports more dtypes."],"exampleFix":"// before\nlet out = int_series.checked_div_num(2.0f64)?; // panics for this dtype\n\n// after\nlet out = int_series.cast(&DataType::Float64)?\n    .checked_div_num(2.0f64)?\n    .cast(int_series.dtype())?;","handlingStrategy":"type-guard","validationCode":"match s.dtype() {\n    DataType::Float64 | DataType::Float32 => { /* supported path */ }\n    _ => { /* cast first */ }\n}","typeGuard":"fn supports_checked_div_num(s: &Series) -> bool {\n    matches!(s.dtype(), DataType::Float64 | DataType::Float32)\n}","tryCatchPattern":null,"preventionTips":["Cast to Float64 before scalar division, then cast back.","Prefer documented operators (`/`, `divide`) which cover more dtypes.","Check the checked_div_num match arms when upgrading polars versions."],"tags":["rust","polars","arithmetic","checked-div","unsupported-dtype"],"backgroundTag":"unsupported-dtype","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"}