Skip to content

BUG: read_csv with engine=pyarrow and numpy-nullable dtype #62053

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jbrockmendel
Copy link
Member

Also makes this code path robust to always-distinguish behavior in #62040

@jbrockmendel jbrockmendel marked this pull request as ready for review August 6, 2025 00:50
Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

From the original issue, do you know where we are introducing float to lose precision when wanting the result type to be int?

@mroeschke mroeschke added the IO CSV read_csv, to_csv label Aug 6, 2025
@jbrockmendel
Copy link
Member Author

From the original issue, do you know where we are introducing float to lose precision when wanting the result type to be int?

In arrow_table_to_pandas the pyarrow[int64] columns get converted to np.float64, then in finalize_pandas_output that gets cast back to Int64.

@mroeschke
Copy link
Member

OK I see, it's pyarrow.Table.to_pandas casting the int to float when there's null.

What if in arrow_table_to_pandas, we always provide fallback type_mapper={pyarrow ints : pandas nullable ints} to avoid the lossy conversions, then afterwards we cast the pandas nullable ints to the appropriate type?

@jbrockmendel
Copy link
Member Author

That’s basically what this is currently doing, just not in that function since it is also called from other places.

I’m out of town for a few days. If you feel strongly that this logic should live inside that function I’ll move it when I get back

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO CSV read_csv, to_csv
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: read_csv loses precision when engine='pyarrow' and dtype Int64
2 participants