Skip to content

BUG: Fix read_parquet not working with data type pyarrow list (#57411) #58156

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,8 @@ def pandas_dtype(dtype) -> DtypeObj:
return dtype.dtype
elif isinstance(dtype, (np.dtype, ExtensionDtype)):
return dtype
elif "list" in str(dtype) and "pyarrow" in str(dtype):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix is too specific and probably doesn't fix the core issue

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mroeschke I second this. A more general fix is needed.

return dtype

# registered extension types
result = registry.find(dtype)
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,20 @@ def test_cross_engine_fp_pa(df_cross_compat, pa, fp):
tm.assert_frame_equal(result, df[["a", "d"]])


def test_pyarrow_list():
pytest.importorskip("fastparquet")
import pyarrow as pa

list_int = pa.list_(pa.int64())
s = pd.Series([[1, 1], [2, 2]], dtype=pd.ArrowDtype(list_int))

df = pd.DataFrame(s, columns=["col"])
df.to_parquet("ex.parquet")

result = read_parquet(path="ex.parquet", dtype_backend="pyarrow")
Copy link
Member

@WillAyd WillAyd Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems off to me - so even with dtype_backend="pyarrow" we are trying to convert it to an object type? I think this should maintain the pyarrow type all the way through

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi William.
I do agree with you and I might be wrong.
But at least for this specific case, the object type is preserved.
Nevertheless, I will try to work on a better solution.

tm.assert_frame_equal(df, result)


class Base:
def check_error_on_write(self, df, engine, exc, err_msg):
# check that we are raising the exception on writing
Expand Down