{"record":{"id":"f8eda866d95be028","repo":"pola-rs/polars","slug":"expected-index-type-found-self","errorCode":null,"errorMessage":"expected index type found {self:?}","messagePattern":"expected index type found (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/datatypes/any_value.rs","lineNumber":677,"sourceCode":"        self.strict_cast(dtype).ok_or_else(\n            || polars_err!(ComputeError: \"cannot cast any-value {:?} to dtype '{}'\", self, dtype),\n        )\n    }\n\n    pub fn cast(&self, dtype: &'a DataType) -> AnyValue<'a> {\n        match self.strict_cast(dtype) {\n            Some(av) => av,\n            None => AnyValue::Null,\n        }\n    }\n\n    pub fn idx(&self) -> IdxSize {\n        match self {\n            #[cfg(not(feature = \"bigidx\"))]\n            Self::UInt32(v) => *v,\n            #[cfg(feature = \"bigidx\")]\n            Self::UInt64(v) => *v,\n            _ => panic!(\"expected index type found {self:?}\"),\n        }\n    }\n\n    pub fn str_value(&self) -> Cow<'a, str> {\n        match self {\n            Self::String(s) => Cow::Borrowed(s),\n            Self::StringOwned(s) => Cow::Owned(s.to_string()),\n            Self::Null => Cow::Borrowed(\"null\"),\n            #[cfg(feature = \"dtype-categorical\")]\n            Self::Categorical(cat, map) | Self::Enum(cat, map) => {\n                Cow::Borrowed(unsafe { map.cat_to_str_unchecked(*cat) })\n            },\n            #[cfg(feature = \"dtype-categorical\")]\n            Self::CategoricalOwned(cat, map) | Self::EnumOwned(cat, map) => {\n                Cow::Owned(unsafe { map.cat_to_str_unchecked(*cat) }.to_owned())\n            },\n            av => Cow::Owned(av.to_string()),\n        }","sourceCodeStart":659,"sourceCodeEnd":695,"githubUrl":"https://github.com/pola-rs/polars/blob/68506541d2de983056c9eb244e1ea05fab377dfc/crates/polars-core/src/datatypes/any_value.rs#L659-L695","documentation":"AnyValue::idx() converts the value to the index type (UInt32, or UInt64 with bigidx); any other variant falls to the panic naming the actual value. It fires when row-index/gather code calls .idx() on a non-index-typed AnyValue, i.e. the value was expected to be a physical index but is another dtype.","triggerScenarios":"This panic/expect fires when execution reaches an unguarded state described by: \"expected index type found {self:?}\". Typical triggers: unsupported dtype or feature-gated code path reached at runtime, invalid user input or environment variable value, calling API methods in the wrong order or on mismatched types, or data (lengths, offsets, ranges) violating the function's preconditions.","commonSituations":"Encountered when input data or configuration does not meet the preconditions of the throwing code path (\"expected index type found {self:?}\"). Common cases: missing Cargo feature flags, mismatched dtypes/lengths between arrays or series, out-of-range temporal values, malformed environment variables, or operations on unsupported/complex nested types.","solutions":["Use an index-typed AnyValue (UInt32/UInt64/Int32/Int64) where an index is expected.","Cast the value to an integer index type before use."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"68506541d2de983056c9eb244e1ea05fab377dfc","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}