Skip to content

BUG: read_parquet doesn't work for ArrowDtype dictionary types. #54392

@randolf-scholz

Description

@randolf-scholz

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
import pyarrow as pa

pa_dict = pa.dictionary(pa.int32(), pa.string())
pd_dict = pd.ArrowDtype(pa_dict)

# create table in pyarrow
data = {"foo": [1,2], "bar": ["a", "b"]}
schema = pa.schema({"foo": pa.int32(), "bar": pa_dict})
table = pa.table(data, schema=schema)

# serialize in arrow and loading to pandas works
pa.parquet.write_table(table, "demo.parquet")
df = pd.read_parquet("demo.parquet", dtype_backend="pyarrow")

assert df.bar.dtype ==  pd_dict  # ✔ the dtype is dictionary[int32,string]

# saving and re-loading doesn't
df.to_parquet("demo2.parquet")
pd.read_parquet("demo2.parquet", dtype_backend="pyarrow")

Issue Description

When attempting to load a DataFrame that was serialized with pandas as a parquet-file the error

ValueError: format number 1 of "dictionary<values=string, indices=int32, ordered=0>[pyarrow]" is not recognized

is raised if the table contained a column with pd.ArrowDtype(pa.dictionary(pa.int32(), pa.string())).

Surprisingly, the same is not true when trying to read the same table if it was serialized as parquet via pyarrow.

Expected Behavior

It should load the DataFrame.

Installed Versions

INSTALLED VERSIONS
------------------
commit           : eaddc1d4815b96f2cdee038c6e26fe7fc9084f13
python           : 3.10.11.final.0
python-bits      : 64
OS               : Linux
OS-release       : 5.19.0-50-generic
Version          : #50-Ubuntu SMP PREEMPT_DYNAMIC Mon Jul 10 18:24:29 UTC 2023
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 2.1.0.dev0+1378.geaddc1d481
numpy            : 1.24.4
pytz             : 2023.3
dateutil         : 2.8.2
setuptools       : 65.5.0
pip              : 23.2.1
Cython           : 0.29.33
pytest           : 7.4.0
hypothesis       : 6.82.0
sphinx           : 6.2.1
blosc            : 1.11.1
feather          : None
xlsxwriter       : 3.1.2
lxml.etree       : 4.9.3
html5lib         : 1.1
pymysql          : 1.4.6
psycopg2         : 2.9.6
jinja2           : 3.1.2
IPython          : 8.14.0
pandas_datareader: None
bs4              : 4.12.2
bottleneck       : 1.3.7
brotli           : 
fastparquet      : 2023.7.0
fsspec           : 2023.6.0
gcsfs            : 2023.6.0
matplotlib       : 3.7.2
numba            : 0.57.1
numexpr          : 2.8.4
odfpy            : None
openpyxl         : 3.1.2
pandas_gbq       : None
pyarrow          : 12.0.1
pyreadstat       : 1.2.2
pyxlsb           : 1.0.10
s3fs             : 2023.6.0
scipy            : 1.11.1
snappy           : 
sqlalchemy       : 2.0.19
tables           : 3.8.0
tabulate         : 0.9.0
xarray           : 2023.7.0
xlrd             : 2.0.1
zstandard        : 0.21.0
tzdata           : 2023.3
qtpy             : None
pyqt5            : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Arrowpyarrow functionalityBugIO Parquetparquet, featherUpstream issueIssue related to pandas dependency

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions