{"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/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/arrow/accessors.py#L180-L216","documentation":"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().","triggerScenarios":"for x in s.list:, list(s.list), or *s.list unpacking on a list[pyarrow] Series.","commonSituations":"Expecting the accessor to yield list elements directly; writing a comprehension over the accessor instead of the data.","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."],"exampleFix":"// before\nfor x in s.list:\n    ...\n// after\nfor x in s.list.flatten():\n    ...","handlingStrategy":"validation","validationCode":"def iter_list_elements(s):\n    return iter(s.list.flatten())","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use .list.flatten() or .explode() to iterate list elements","Never iterate the accessor object itself"],"tags":["pyarrow","list-accessor","iteration","type-error"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}