{"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/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/datatypes/any_value.rs#L659-L695","documentation":"AnyValue::idx() extracts the index-sized physical value (IdxSize = u32, or u64 with the 'bigidx' feature). If the AnyValue holds any other variant the code panics, because idx() is only meaningful for values that are actually row indices.","triggerScenarios":"Calling av.idx() on an AnyValue that is Int32/Int64/UInt64 (when bigidx is off) or any non-integer variant; reading row-index values from a series compiled with a different bigidx setting than your code expects.","commonSituations":"Generic code assuming idx-typed values are u32 while the crate was built with bigidx (or vice versa); calling idx() on values extracted from arbitrary columns.","solutions":["Match the AnyValue yourself and convert with as_idx-style logic handling both UInt32 and UInt64 variants.","Ensure the bigidx feature setting is consistent between polars-core and your code / dependent crates (cargo tree -f for polars-core builds).","Use av.extract::<IdxSize>() or downcast the series to IdxCa instead of idx().","Guard with a check that the value is one of the accepted UInt variants before calling idx()."],"exampleFix":"// before\nlet idx = av.idx(); // panics for UInt64 when bigidx is off\n// after\nlet idx = match av {\n    AnyValue::UInt32(v) => v as IdxSize,\n    AnyValue::UInt64(v) => IdxSize::try_from(v).expect(\"index overflow\"),\n    _ => return Err(PolarsError::ComputeError(\"not an index value\".into())),\n};","handlingStrategy":"type-guard","validationCode":"fn to_idx(av: &AnyValue) -> Option<IdxSize> {\n    match av {\n        AnyValue::UInt32(v) => Some(*v),\n        AnyValue::UInt64(v) => IdxSize::try_from(*v).ok(),\n        _ => None,\n    }\n}","typeGuard":"let idx = to_idx(&av).ok_or_else(|| PolarsError::ComputeError(\"not an index\".into()))?;","tryCatchPattern":null,"preventionTips":["Match UInt32/UInt64 variants explicitly instead of calling idx()","Keep the bigidx feature consistent across the whole dependency tree","Only use idx() on values known to come from index-typed columns"],"tags":["polars","panic","index","feature-flag"],"backgroundTag":"type-mismatch","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"}