{"record":{"id":"f908adbff5b9a2f2","repo":"pandas-dev/pandas","slug":"can-only-use-the-list-accessor-with-list-pyarr","errorCode":null,"errorMessage":"Can only use the '.list' accessor with 'list[pyarrow]' dtype, not {dtype}.","messagePattern":"Can only use the '\\.list' accessor with 'list\\[pyarrow\\]' dtype, not (.+?)\\.","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/arrow/accessors.py","lineNumber":48,"sourceCode":"    )\n\n\nclass ArrowAccessor(metaclass=ABCMeta):\n    @abstractmethod\n    def __init__(self, data, validation_msg: str) -> None:\n        self._data = data\n        self._validation_msg = validation_msg\n        self._validate(data)\n\n    @abstractmethod\n    def _is_valid_pyarrow_dtype(self, pyarrow_dtype) -> bool:\n        pass\n\n    def _validate(self, data) -> None:\n        dtype = data.dtype\n        if not HAS_PYARROW or not isinstance(dtype, ArrowDtype):\n            # Raise AttributeError so that inspect can handle non-struct Series.\n            raise AttributeError(self._validation_msg.format(dtype=dtype))\n\n        if not self._is_valid_pyarrow_dtype(dtype.pyarrow_dtype):\n            # Raise AttributeError so that inspect can handle invalid Series.\n            raise AttributeError(self._validation_msg.format(dtype=dtype))\n\n    @property\n    def _pa_array(self):\n        return self._data.array._pa_array\n\n\nclass ListAccessor(ArrowAccessor):\n    \"\"\"\n    Accessor object for list data properties of the Series values.\n\n    Parameters\n    ----------\n    data : Series\n        Series containing Arrow list data.","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/arrow/accessors.py#L30-L66","documentation":"The .list accessor only works on Series of dtype list[pyarrow] (including large_list and fixed_size_list). Line 48 raises AttributeError specifically when the dtype is not even an ArrowDtype (e.g. object, int64, pandas string) or pyarrow is not installed. AttributeError (not ValueError) is used so that hasattr/inspect treat the accessor as absent on non-list Series.","triggerScenarios":"s.list.len() (or any s.list method) on a Series of Python lists stored as object dtype, or on int64 / pandas string / float dtype.","commonSituations":"Forgetting to convert an object-dtype list column to list[pyarrow] before using .list; reading JSON/nested data without specifying the arrow dtype.","solutions":["Convert the column to list[pyarrow]: pd.Series(s, dtype=pd.ArrowDtype(pa.list_(pa.int64()))).","For object-dtype list columns, use s.apply(len) / s.explode() instead of the .list accessor."],"exampleFix":"// before\ns.list.len()  # s.dtype == object\n// after\nimport pyarrow as pa\ns = s.astype(pd.ArrowDtype(pa.list_(pa.int64())))\ns.list.len()","handlingStrategy":"type-guard","validationCode":"def to_list_pa(s, value_type=pa.int64()):\n    from pandas.core.dtypes.dtypes import ArrowDtype\n    if not (isinstance(s.dtype, ArrowDtype) and (\n        pa.types.is_list(s.dtype.pyarrow_dtype)\n        or pa.types.is_large_list(s.dtype.pyarrow_dtype)\n        or pa.types.is_fixed_size_list(s.dtype.pyarrow_dtype)\n    )):\n        s = pd.Series(list(s), dtype=ArrowDtype(pa.list_(value_type)))\n    return s","typeGuard":"def is_list_pyarrow(s) -> bool:\n    import pyarrow as pa\n    from pandas.core.dtypes.dtypes import ArrowDtype\n    d = s.dtype\n    return isinstance(d, ArrowDtype) and (\n        pa.types.is_list(d.pyarrow_dtype)\n        or pa.types.is_large_list(d.pyarrow_dtype)\n        or pa.types.is_fixed_size_list(d.pyarrow_dtype)\n    )","tryCatchPattern":null,"preventionTips":["Convert list columns to list[pyarrow] before using .list","Guard dynamic-dtype code with hasattr(s, 'list') or an explicit type check"],"tags":["pyarrow","list-accessor","dtype","attribute-error"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}