pola-rs/polars · error
expected index type found {self:?}
Error message
expected index type found {self:?} What it means
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.
Source
Thrown at crates/polars-core/src/datatypes/any_value.rs:677
self.strict_cast(dtype).ok_or_else(
|| polars_err!(ComputeError: "cannot cast any-value {:?} to dtype '{}'", self, dtype),
)
}
pub fn cast(&self, dtype: &'a DataType) -> AnyValue<'a> {
match self.strict_cast(dtype) {
Some(av) => av,
None => AnyValue::Null,
}
}
pub fn idx(&self) -> IdxSize {
match self {
#[cfg(not(feature = "bigidx"))]
Self::UInt32(v) => *v,
#[cfg(feature = "bigidx")]
Self::UInt64(v) => *v,
_ => panic!("expected index type found {self:?}"),
}
}
pub fn str_value(&self) -> Cow<'a, str> {
match self {
Self::String(s) => Cow::Borrowed(s),
Self::StringOwned(s) => Cow::Owned(s.to_string()),
Self::Null => Cow::Borrowed("null"),
#[cfg(feature = "dtype-categorical")]
Self::Categorical(cat, map) | Self::Enum(cat, map) => {
Cow::Borrowed(unsafe { map.cat_to_str_unchecked(*cat) })
},
#[cfg(feature = "dtype-categorical")]
Self::CategoricalOwned(cat, map) | Self::EnumOwned(cat, map) => {
Cow::Owned(unsafe { map.cat_to_str_unchecked(*cat) }.to_owned())
},
av => Cow::Owned(av.to_string()),
}View on GitHub (pinned to 68506541d2)
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.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: 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.
Common situations: 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.
AI-assisted analysis of pola-rs/polars@68506541d2 (2026-08-19).
Data as JSON: /api/errors/f8eda866d95be028.
Report an issue: GitHub.