pola-rs/polars · error · TypeError
expected type 'int | str', got {qualified_type_name(item)!r}
Error message
expected type 'int | str', got {qualified_type_name(item)!r} What it means
Subscript guard on StructNameSpace: __getitem__ was called with an item that is neither an int (field index) nor a str (field name) — e.g. a slice or tuple. The qualified type name of the offending item is included in the message.
Source
Thrown at py-polars/src/polars/series/struct.py:43:44
def __getitem__(self, item: int | str) -> Series:
if isinstance(item, int):
return self.field(self.fields[item])
elif isinstance(item, str):
return self.field(item)
else:
msg = f"expected type 'int | str', got {qualified_type_name(item)!r}"
raise TypeError(msg)View on GitHub (pinned to 9b5d73fd00)
Solutions
- Index the struct namespace with an int position or a str field name, e.g. `s.struct[0]` or `s.struct['field_name']`.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at py-polars/src/polars/struct.py:44 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of pola-rs/polars@9b5d73fd00 (2026-08-19).
Data as JSON: /api/errors/5d6c6d7e19e2a8e7.
Report an issue: GitHub.