Skip to content

BUG: Regression when using .str[...] accessor on ArrowExtensionArray #65112

@tehunter

Description

@tehunter

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

>>> import pandas as pd
>>> x = pd.Series(["abc"])
>>> x.str[0]
0    a
dtype: str
>>> x_converted = x.convert_dtypes(dtype_backend="pyarrow")
>>> x_converted.str[0]
Traceback (most recent call last):
  File "<python-input-4>", line 1, in <module>
    x_converted.str[0]
    ~~~~~~~~~~~~~~~^^^
  File "...\pandas\core\strings\accessor.py", line 254, in __getitem__
    result = self._data.array._str_getitem(key)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'ArrowExtensionArray' object has no attribute '_str_getitem'. Did you mean: '_str_istitle'?

Issue Description

When using .convert_dtypes(dtype_backend="pyarrow"), the underlying array of string types is an ArrowExtensionArray. Previously, this class inherited string methods from ArrowStringArrayMixin and BaseStringArrayMethods. However, in 3.0.0, that was changed to remove BaseStringArrayMethods (#62155).

Unfortunately, BaseStringArrayMethods does not have full parity with ArrowStringArrayMixin. I did a quick search of the other differences, and _str_getitem appears to be the only difference that causes this problem.

I think ArrowStringArrayMixin or ArrowExtensionArray should implement the _str_getitem method, though another solution would be to have .convert_dtypes(dtype_backend="pyarrow") to produce an ArrayStringArray instead of an ArrowExtensionArray for string columns. I'm not familiar enough with the details of these types to know why we would prefer the latter.

Expected Behavior

x.str[0] works for any string-typed x

Installed Versions

Details

INSTALLED VERSIONS

commit : ab90747
python : 3.13.9
python-bits : 64
OS : Windows
OS-release : 11
Version :
machine :
processor :
byteorder : little
LC_ALL : None
LANG : None
LOCALE :

pandas : 3.0.2
numpy : 2.4.4
dateutil : 2.9.0.post0
pip : None
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
psycopg2 : None
pymysql : None
pyarrow : 23.0.1
pyiceberg : None
pyreadstat : None
pytest : None
python-calamine : None
pytz : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions