You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "AlenkaF (via GitHub)" <gi...@apache.org> on 2025/06/23 08:37:58 UTC
Re: [I] [Python] read_csv converts strings with leading zeros to integers [arrow]
AlenkaF commented on issue #46853:
URL: https://github.com/apache/arrow/issues/46853#issuecomment-2995475317
Correct, this is something to be expected, see [type inference docs](https://arrow.apache.org/docs/cpp/csv.html#data-types). You can change the column type and disable type inference with `column_types` in [`pa.csv.ConvertOptions`](https://arrow.apache.org/docs/python/generated/pyarrow.csv.ConvertOptions.html#pyarrow-csv-convertoptions):
```python
In [45]: convert_options=csv.ConvertOptions(
...: column_types={
...: 'col1': pa.string(),
...: }
...: )
...: with io.BytesIO(b'col1,col2\n"001","foo"\n"002","bar"') as buf:
...: tbl = csv.read_csv(buf, parse_options=pa.csv.ParseOptions(quote_char='"'),
...: convert_options=convert_options)
...: print(tbl)
...:
pyarrow.Table
col1: string
col2: string
----
col1: [["001","002"]]
col2: [["foo","bar"]]
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org