Description
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
df = pd.DataFrame({"foo": [1, 2, 3], "bar": list("abc")})
df = df.convert_dtypes(dtype_backend="pyarrow")
df.to_parquet("dataset", partition_cols=["bar"])
pd.read_parquet("dataset") # raises ValueError
Issue Description
When reading parquet datasets partitioned by a column of type string[pyarrow]
, it crashes with the following error:
Traceback (most recent call last):
File "/tmp/foo.py", line 5, in <module>
pd.read_parquet("dataset")
File "/tmp/venv/lib/python3.11/site-packages/pandas/io/parquet.py", line 509, in read_parquet
return impl.read(
^^^^^^^^^^
File "/tmp/venv/lib/python3.11/site-packages/pandas/io/parquet.py", line 230, in read
result = pa_table.to_pandas(**to_pandas_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "pyarrow/array.pxi", line 837, in pyarrow.lib._PandasConvertible.to_pandas
File "pyarrow/table.pxi", line 4114, in pyarrow.lib.Table._to_pandas
File "/tmp/venv/lib/python3.11/site-packages/pyarrow/pandas_compat.py", line 820, in table_to_blockmanager
blocks = _table_to_blocks(options, table, categories, ext_columns_dtypes)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/venv/lib/python3.11/site-packages/pyarrow/pandas_compat.py", line 1170, in _table_to_blocks
return [_reconstruct_block(item, columns, extension_columns)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/venv/lib/python3.11/site-packages/pyarrow/pandas_compat.py", line 1170, in <listcomp>
return [_reconstruct_block(item, columns, extension_columns)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/venv/lib/python3.11/site-packages/pyarrow/pandas_compat.py", line 780, in _reconstruct_block
pd_ext_arr = pandas_dtype.__from_arrow__(arr)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/venv/lib/python3.11/site-packages/pandas/core/arrays/string_.py", line 196, in __from_arrow__
return ArrowStringArray(array)
^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/venv/lib/python3.11/site-packages/pandas/core/arrays/string_arrow.py", line 116, in __init__
raise ValueError(
ValueError: ArrowStringArray requires a PyArrow (chunked) array of string type
Expected Behavior
I would expect pandas to correctly open the partitioned parquet dataset. If I change the "bar" column dtype to str
, it works, as follows:
import pandas as pd
df = pd.DataFrame({"foo": [1, 2, 3], "bar": list("abc")})
df = df.convert_dtypes(dtype_backend="pyarrow").astype({"bar": str})
df.to_parquet("dataset", partition_cols=["bar"])
pd.read_parquet("dataset") # now this works
Installed Versions
/tmp/venv/lib/python3.11/site-packages/_distutils_hack/init.py:33: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")
INSTALLED VERSIONS
commit : 0f43794
python : 3.11.3.final.0
python-bits : 64
OS : Linux
OS-release : 6.3.9-arch1-1
Version : #1 SMP PREEMPT_DYNAMIC Wed, 21 Jun 2023 20:46:20 +0000
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.0.3
numpy : 1.25.0
pytz : 2023.3
dateutil : 2.8.2
setuptools : 65.5.0
pip : 22.3.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.14.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 12.0.1
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None