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} ({item!r}) What it means
Error "expected type 'int | str', got {qualified_type_name(item)!r} ({item!r})" thrown in pola-rs/polars.
Source
Thrown at py-polars/src/polars/datatype_expr/struct.py:24
class DataTypeExprStructNameSpace:
"""Namespace for struct datatype expressions."""
_accessor = "struct"
def __init__(self, expr: pl.DataTypeExpr) -> None:
self._pydatatype_expr = expr._pydatatype_expr
def __getitem__(self, item: str | int) -> pl.DataTypeExpr:
if isinstance(item, str):
return self.field_dtype(item)
elif isinstance(item, int):
return pl.DataTypeExpr._from_pydatatype_expr(
self._pydatatype_expr.struct_field_dtype_by_index(item)
)
else:
msg = f"expected type 'int | str', got {qualified_type_name(item)!r} ({item!r})"
raise TypeError(msg)
def field_dtype(self, field_name: str) -> pl.DataTypeExpr:
"""
Get the DataType of field with a specific field name.
Notes
-----
The `struct` namespace has implemented `__getitem__` so you can also access
fields by index:
>>> (
... pl.Struct({"x": pl.Int64, "y": pl.String})
... .to_dtype_expr()
... .struct[1]
... .collect_dtype({})
... )
StringView on GitHub (pinned to df599052da)
When it happens
Trigger: Thrown at py-polars/src/polars/datatype_expr/struct.py:24 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16).
Data as JSON: /api/errors/384f2c4f7b71ecf0.
Report an issue: GitHub.