{"record":{"id":"30593beaa95d4f8b","repo":"pola-rs/polars","slug":"operation-not-supported-for-dtype","errorCode":null,"errorMessage":"`{}` operation not supported for dtype `{}`","messagePattern":"`(.+?)` operation not supported for dtype `(.+?)`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/series/mod.rs","lineNumber":10,"sourceCode":"#![allow(unsafe_op_in_unsafe_fn)]\n//! Type agnostic columnar data structure.\nuse crate::chunked_array::flags::StatisticsFlags;\npub use crate::prelude::ChunkCompareEq;\nuse crate::prelude::*;\nuse crate::{HEAD_DEFAULT_LENGTH, TAIL_DEFAULT_LENGTH};\n\nmacro_rules! invalid_operation_panic {\n    ($op:ident, $s:expr) => {\n        panic!(\n            \"`{}` operation not supported for dtype `{}`\",\n            stringify!($op),\n            $s._dtype()\n        )\n    };\n}\n\npub mod amortized_iter;\nmod any_value;\npub mod arithmetic;\npub mod arrow_export;\npub mod builder;\n\nmod comparison;\nmod from;\npub mod implementations;\npub(crate) mod iterator;\npub mod ops;","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/series/mod.rs#L1-L28","documentation":"polars-core's Series defines an `invalid_operation_panic!` macro used throughout series/method implementations: when an operation (add, sub, eq, rem, etc.) is applied to a dtype that does not implement it, the code panics with '`<op>` operation not supported for dtype `<dtype>`'. It is the catch-all arm of dtype-dispatched operators in crates/polars-core/src/series/mod.rs and sibling impls.","triggerScenarios":"Applying arithmetic/comparison operators on Series with unsupported dtypes, e.g. `bool_series + bool_series`, subtracting two String Series, bitwise/remainder ops on temporal or nested dtypes; dispatching generic operations across all DataFrame columns where some column dtype lacks the operator impl.","commonSituations":"Generic code summing every column of a DataFrame; boolean columns mistakenly treated as 0/1 numerics; String columns loaded from CSV being used in arithmetic before a `str.to_integer()`/cast.","solutions":["Check `series.dtype()` and cast to a compatible numeric dtype before applying the operator.","For booleans, use logical ops (&, |) or cast to UInt8 for arithmetic.","For strings used numerically, apply `cast(DataType::Int64)`/`str.to_integer()` first.","Skip or handle non-numeric columns explicitly in generic per-column loops."],"exampleFix":"// before\nlet total = &bool_col_a + &bool_col_b; // panics\n\n// after\nlet total = &bool_col_a.cast(&DataType::UInt8)? + &bool_col_b.cast(&DataType::UInt8)?;","handlingStrategy":"type-guard","validationCode":"fn is_numeric(s: &Series) -> bool {\n    s.dtype().is_numeric()\n}\nif !is_numeric(&a) || !is_numeric(&b) { /* skip or cast */ }","typeGuard":"fn numeric_pair(a: &Series, b: &Series) -> Option<(Series, Series)> {\n    (a.dtype().is_numeric() && b.dtype().is_numeric())\n        .then(|| (a.clone(), b.clone()))\n}","tryCatchPattern":null,"preventionTips":["Guard operators with dtype checks in generic per-column code.","Cast bools to numeric and strings to integers before arithmetic.","Inspect `df.schema()` after reading external data before computing."],"tags":["rust","polars","operators","dtype","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"}