Skip to content
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

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

Closed
wants to merge 1 commit into from

Conversation

diogojarodrigues
Copy link

When writing a DataFrame to a Parquet file, if the data type of the columns of the DataFrame is a PyArrow list, an error is raised when reading it from the Parquet file.

The error occurs because when reading, pandas tries to use NumPy dtypes which do not support PyArrow lists (in the function pandas_dtype in the file ./pandas/core/dtypes/common.py).

To solve this issue, we add an if statement to check if the column's data type is a PyArrow list. If so, we return the data type without converting it into a NumPy dtype (which does not support PyArrow lists).

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.

@WillAyd
Copy link
Member

WillAyd commented Apr 5, 2024

Thanks for the PR

@WillAyd WillAyd added Dtype Conversions Unexpected or buggy dtype conversions Arrow pyarrow functionality labels Apr 5, 2024
@@ -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.

@diogojarodrigues
Copy link
Author

Thanks for the feedback.
I will try to make some changes and afterward I will update my pull request.

@mroeschke
Copy link
Member

Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.

@mroeschke mroeschke closed this May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: read_parquet gives TypeError if dtype is a pyarrow list
4 participants