-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -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 isinstance( | ||||||||
type(self.kwds.get("dtype")), dict | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
): | ||||||||
frame = table.to_pandas(types_mapper=self.kwds["dtype"].get) | ||||||||
else: | ||||||||
frame = table.to_pandas() | ||||||||
return self._finalize_pandas_output(frame) |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -558,3 +558,24 @@ def test_string_inference(all_parsers): | |||
columns=pd.Index(["a", "b"], dtype=dtype), | ||||
) | ||||
tm.assert_frame_equal(result, expected) | ||||
|
||||
|
||||
def test_accurate_parsing_of_large_integers(all_parsers): | ||||
# GH#52505 | ||||
data = """SYMBOL,SYSTEM,TYPE,MOMENT,ID,ACTION,PRICE,VOLUME,ID_DEAL,PRICE_DEAL | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you reduce the unnecessary data for testing? |
||||
AAPL,F,S,20230301181139587,1925036343869802844,0,96690.00000,2,,75.00000 | ||||
MSFT,F,S,20230301181139587,2023552585717888193,0,75.10000,14,, | ||||
TSLA,F,S,20230301181139587,2023552585717889863,1,75.00000,14,, | ||||
AAPL,F,S,20230301181139587,2023552585717889863,2,75.00000,1,2023552585717263358,75.00000 | ||||
TSLA,F,B,20230301181139587,2023552585717882895,2,75.00000,1,2023552585717263358,75.00000 | ||||
NVDA,F,S,20230301181139587,2023552585717889863,2,75.00000,1,2023552585717263359,75.00000 | ||||
MRNA,F,B,20230301181139587,2023552585717888161,2,75.00000,1,2023552585717263359,75.00000 | ||||
AMC,F,S,20230301181139587,2023552585717889863,2,75.00000,10,2023552585717263360,75.00000 | ||||
AMZN,F,B,20230301181139587,2023552585717889759,2,75.00000,10,2023552585717263360,75.00000 | ||||
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"))) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
tm.assert_equal( | ||||
len(orders.query("ID_DEAL==2023552585717263360", engine="python")), 2 | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you not use Also a plain |
||||
) |
There was a problem hiding this comment.
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?