pandas-dev/pandas · error · TypeError
'{type(self).__name__}' object is not iterable
Error message
'{type(self).__name__}' object is not iterable What it means
ListAccessor explicitly defines __iter__ to raise TypeError, so you cannot iterate the accessor object itself. This prevents 'for x in s.list' from silently doing nothing meaningful; to iterate list elements you must first materialize them via .flatten() or .explode().
Source
Thrown at pandas/core/arrays/arrow/accessors.py:198
if start is None:
# TODO: When adding negative step support
# this should be set to last element of array
# when step is negative.
start = 0
if step is None:
step = 1
sliced = pc.list_slice(self._pa_array, start, stop, step)
return Series(
sliced,
dtype=ArrowDtype(sliced.type),
index=self._data.index,
name=self._data.name,
)
else:
raise ValueError(f"key must be an int or slice, got {type(key).__name__}")
def __iter__(self) -> Iterator:
raise TypeError(f"'{type(self).__name__}' object is not iterable")
def flatten(self) -> Series:
"""
Flatten list values.
Each list element is expanded into separate rows, preserving the
original index. The resulting Series may have a longer length than
the original if lists contain more than one element.
Returns
-------
pandas.Series
The data from all lists in the series flattened.
See Also
--------
ListAccessor.__getitem__ : Index or slice values in the Series.
View on GitHub (pinned to 71959b8cb9)
Solutions
- Use s.list.flatten() (or s.explode()) to get elements, then iterate the resulting Series.
- Use s.tolist() / s.apply(list) when you need plain Python lists.
Example fix
// before
for x in s.list:
...
// after
for x in s.list.flatten():
... Defensive patterns
Strategy: validation
Validate before calling
def iter_list_elements(s):
return iter(s.list.flatten()) Prevention
- Use .list.flatten() or .explode() to iterate list elements
- Never iterate the accessor object itself
When it happens
Trigger: for x in s.list:, list(s.list), or *s.list unpacking on a list[pyarrow] Series.
Common situations: Expecting the accessor to yield list elements directly; writing a comprehension over the accessor instead of the data.
Related errors
- Can only use the '.list' accessor with 'list[pyarrow]' dtype
- key must be an int or slice, got {type(key).__name__}
- __invert__ is not supported for string dtypes
- unary '-' not supported for dtype '{self.dtype}'
- operation '{op.__name__}' not supported for dtype '{self.dty
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/e91b2ea7298862ac.
Report an issue: GitHub.