{"record":{"id":"e91b2ea7298862ac","repo":"pandas-dev/pandas","slug":"type-self-name-object-is-not-iterable","errorCode":null,"errorMessage":"'{type(self).__name__}' object is not iterable","messagePattern":"'(.+?)' object is not iterable","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/arrow/accessors.py","lineNumber":198,"sourceCode":"            if start is None:\n                # TODO: When adding negative step support\n                #  this should be set to last element of array\n                # when step is negative.\n                start = 0\n            if step is None:\n                step = 1\n            sliced = pc.list_slice(self._pa_array, start, stop, step)\n            return Series(\n                sliced,\n                dtype=ArrowDtype(sliced.type),\n                index=self._data.index,\n                name=self._data.name,\n            )\n        else:\n            raise ValueError(f\"key must be an int or slice, got {type(key).__name__}\")\n\n    def __iter__(self) -> Iterator:\n        raise TypeError(f\"'{type(self).__name__}' object is not iterable\")\n\n    def flatten(self) -> Series:\n        \"\"\"\n        Flatten list values.\n\n        Each list element is expanded into separate rows, preserving the\n        original index. The resulting Series may have a longer length than\n        the original if lists contain more than one element.\n\n        Returns\n        -------\n        pandas.Series\n            The data from all lists in the series flattened.\n\n        See Also\n        --------\n        ListAccessor.__getitem__ : Index or slice values in the Series.\n","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/arrow/accessors.py#L180-L216","documentation":"`TypeError(\"'{type}' object is not iterable\")` from `ListAccessor.__iter__`. The accessor deliberately disables iteration: iterating the accessor object itself is meaningless (you want to iterate the Series, or use `.flatten()`/`.list[i]`). Implementing `__getitem__` would otherwise make Python silently call `__iter__` in `for` loops and produce confusing results, so pandas raises explicitly.","triggerScenarios":"`for x in s.list:`; `list(s.list)`; `*rest, = s.list`; any context that triggers Python's iteration protocol on the `ListAccessor` object.","commonSituations":"Assuming `s.list` yields the per-row lists; confusing the accessor with the underlying Series; refactoring from `for row in s:` to `for row in s.list:`.","solutions":["Iterate the Series instead: `for row in s:` gives each row (a Python list).","To work flat, use `s.list.flatten()` and iterate the result.","To get a Python list of the lists: `s.to_numpy().tolist()`."],"exampleFix":"// before\nfor sub in s.list:   # TypeError\n    ...\n\n// after\nfor sub in s:        # iterate the Series\n    ...\n# or\nflat = s.list.flatten()","handlingStrategy":"type-guard","validationCode":"# do not iterate the accessor; iterate the Series\nfor row in s:\n    process(row)","typeGuard":"def is_iterable_target(obj) -> bool:\n    # the Series is iterable; the ListAccessor is not\n    import pandas as pd\n    return isinstance(obj, (pd.Series, list, tuple))","tryCatchPattern":"try:\n    for sub in s.list:\n        ...\nexcept TypeError as e:\n    if 'not iterable' in str(e):\n        for sub in s:\n            ...\n    else:\n        raise","preventionTips":["Iterate the Series, not the accessor","Use s.list.flatten() to iterate flattened elements"],"tags":["accessor","list","iteration","pyarrow"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}