-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: documented usage of of str.split(...).str.get
fails on dtype large_string[pyarrow]
#61431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the report! Agreed on the inconsistency here. print(pd.Series(["abc"], dtype="large_string[pyarrow]").str.split("b"))
# 0 ['a' 'c']
# dtype: list<item: large_string>[pyarrow]
print(pd.Series(["abc"], dtype="string[pyarrow]").str.split("b"))
# 0 [a, c]
# dtype: object The behavior on While the current behavior of returning ArrowExtensionArray list dtype on cc @WillAyd @mroeschke for any thoughts as well. |
This is a general issue that I was hoping the logical type system proposal would clarify, as it gets pretty tough to cherry pick different code paths for different data types. I think the best solution would return a list data type as a result of this operation. It is more inline with the intent of the user code, and more performant |
@WillAyd - which operation? |
str.split |
On both |
👍 |
Thanks @SandroCasagrande for the report. I completely understand the confusion around pandas dtypes and why one could expect the behavior to be different or even lead one to expect consistency here. Let's start by introducing a quirk of pandas and then expanding on that. There's a dtype in pandas core called pd.Series(["abc"], dtype=pd.ArrowDtype(pa.string()))
# 0 abc
# dtype: string[pyarrow] we see this gives pd.Series(["abc"], dtype="string[pyarrow]")
# 0 abc
# dtype: string Oh. The string alias of the dtype is now just string! So let's do that instead. pd.Series(["abc"], dtype="string")
# 0 abc
# dtype: string The quirk is that all these Series are different! The last one is not even backed by PyArrow! So what's going on? pd.Series(["abc"], dtype=pd.ArrowDtype(pa.string())).dtype # string[pyarrow]
type(_) # pandas.core.dtypes.dtypes.ArrowDtype
pd.Series(["abc"], dtype="string[pyarrow]").dtype # string[pyarrow]
type(_) # pandas.core.arrays.string_.StringDtype
pd.Series(["abc"], dtype="string").dtype # string[python]
type(_) # pandas.core.arrays.string_.StringDtype Basically there's overlap in the dtype string aliases for the
so the basic problem here is that Hopefully this background will help the discussion in determining if this is indeed a bug and whether there should be consistency here. |
Indeed ..
We should, eventually, indeed return a list data type, once we have a dedicated list data type. But again my position is that we should only do this for the default dtypes once we have a default list dtype. And so until we have a better logical dtype system, I think the default behaviour for the default string dtype for (if the default string dtype, which uses NaN as missing value indicator, would return a ArrowDtype(list) type, that would introduce NA-variants of dtypes in existing workflows of people that did not opt in into using pyarrow-NA-dtypes) |
And to be clear, we have approval to implement this in PDEP-10. So no blockers here.
Just like PDEP-14 introduced a numpy semantics nan-variant, we also require a numpy semantics variant of the nested dtype. (this perhaps requires a PDEP to mirror PDEP-14 but specific for the nested dtypes) |
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
Issue Description
The return dtype of
split
is very different when acting onlarge_string
(results in pyarrow list) andstring
(results in object).Interestingly, using the
list
accessor works only onlarge_string
dtypebut not on
string
dtypeFrom a use perspective this is unfortunate, as I have to know the underlying dtype in order to choose the correct accessor (or cast).
Expected Behavior
Should work similar to
since it is documented behavior
pandas/doc/source/user_guide/text.rst
Line 229 in f496acf
Installed Versions
INSTALLED VERSIONS
commit : f496acf
python : 3.13.2
python-bits : 64
OS : Darwin
OS-release : 24.4.0
Version : Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:47 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 3.0.0.dev0+2100.gf496acffcc
numpy : 2.2.5
dateutil : 2.9.0.post0
pip : 25.1
Cython : 3.0.11
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 : 20.0.0
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
tzdata : 2025.2
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: