Skip to content

FIX: Solving Int64 precision loss when read_csv(StringIO(data), dtype… #56253

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 2 commits into from

Conversation

thiago0003
Copy link

…={"a": "Int64"}, engine=pyarrow)

[] closes BUG: read_csv losing precision when reading Int64[pyarrow] data with N/A values #56135 and BUG: read_csv loses precision when engine='pyarrow' and dtype Int64 #56136
Tests added and passed if fixing a bug or adding a new feature
All code checks passed.
Added type annotations to new arguments/methods/functions.

Enable the integer_object_nulls option by setting it to True in the following line of code in the "arrow_parser_wrapper.py" file:
table.to_pandas(types_mapper=self.kwds["dtype"].get, integer_object_nulls=True)
This adjustment is crucial when using the "pyarrow" engine as a parameter for the 'read_csv' function. It ensures that columns containing integers (Int64) with null elements within a dataframe maintain their precision. Without this setting, numpy may treat columns with null elements by converting the entire column data to Float, leading to precision loss. Enabling 'integer_object_nulls' prevents this issue and preserves the precision of integer data.

Copy link
Member

@phofl phofl left a comment

Choose a reason for hiding this comment

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

Please change relevant files only

This fix has huge performance implications, I'd rather not do that

@mroeschke
Copy link
Member

Thanks for the PR, but appears this is already being worked on in #56251 so closing in favor of that PR

@mroeschke mroeschke closed this Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: read_csv losing precision when reading Int64[pyarrow] data with N/A values
3 participants