Skip to content

Incorrect reading of CSV containing large integers Issue#52505 #54679

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

Merged
merged 4 commits into from
Aug 24, 2023

Conversation

kvn4
Copy link
Contributor

@kvn4 kvn4 commented Aug 21, 2023

@kvn4 kvn4 changed the title mend Incorrect reading of CSV containing large integers Issue#52505 Aug 21, 2023
@@ -223,5 +223,10 @@ def read(self) -> DataFrame:
elif using_pyarrow_string_dtype():
frame = table.to_pandas(types_mapper=arrow_string_types_mapper())
else:
frame = table.to_pandas()
if self.kwds.get("dtype") is not None and issubclass(
Copy link
Member

Choose a reason for hiding this comment

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

Can you use isinstance instead of issubclass?

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.

This needs a tests and a whatsnew note in 2.2.0.rst

@mroeschke mroeschke added Bug IO CSV read_csv, to_csv Arrow pyarrow functionality labels Aug 22, 2023
@@ -139,7 +139,7 @@ Timezones

Numeric
^^^^^^^
-
- Bug in :func:`_read`, pyarrow engine not defaulting to float64 causing precision errors when specifying a dtype; fixed by explicitly setting dtype if dtype not none and isinstance of dict (:issue:`52505`)
Copy link
Member

Choose a reason for hiding this comment

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

Can you phrase this in terms of a public API?


def test_accurate_parsing_of_large_integers(all_parsers):
# GH#52505
data = """SYMBOL,SYSTEM,TYPE,MOMENT,ID,ACTION,PRICE,VOLUME,ID_DEAL,PRICE_DEAL
Copy link
Member

Choose a reason for hiding this comment

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

Can you reduce the unnecessary data for testing?

MSFT,F,S,20230301181139587,2023552585717889863,2,75.00000,2,2023552585717263361,75.00000
NVDA,F,B,20230301181139587,2023552585717889827,2,75.00000,2,2023552585717263361,75.00000"""
orders = pd.read_csv(StringIO(data), dtype={"ID_DEAL": pd.Int64Dtype()})
print(len(orders.query("ID_DEAL==2023552585717263360", engine="python")))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
print(len(orders.query("ID_DEAL==2023552585717263360", engine="python")))

orders = pd.read_csv(StringIO(data), dtype={"ID_DEAL": pd.Int64Dtype()})
print(len(orders.query("ID_DEAL==2023552585717263360", engine="python")))
tm.assert_equal(
len(orders.query("ID_DEAL==2023552585717263360", engine="python")), 2
Copy link
Member

Choose a reason for hiding this comment

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

Can you not use query here?

Also a plain assert should be fine

@@ -139,7 +139,7 @@ Timezones

Numeric
^^^^^^^
-
- Bug in :func:`_read`, pyarrow engine defaulting to float64 causing rounding errors for large integers; now processes input appropriately (:issue:`52505`)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Bug in :func:`_read`, pyarrow engine defaulting to float64 causing rounding errors for large integers; now processes input appropriately (:issue:`52505`)
- Bug in :func:`read_csv` with `engine="pyarrow"` causing rounding errors for large integers (:issue:`52505`)

Comment on lines 226 to 227
if self.kwds.get("dtype") is not None and isinstance(
type(self.kwds.get("dtype")), dict
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if self.kwds.get("dtype") is not None and isinstance(
type(self.kwds.get("dtype")), dict
if isinstance(self.kwds.get("dtype"), dict):

@mroeschke mroeschke added this to the 2.2 milestone Aug 24, 2023
@mroeschke mroeschke merged commit 766e2fc into pandas-dev:main Aug 24, 2023
@mroeschke
Copy link
Member

Thanks @kvn4

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

Successfully merging this pull request may close these issues.

BUG: incorrect reading of CSV containing large integers
2 participants