Skip to content

BUG: unexpected behavior in read_csv with pyarrow engine and dtype string #57100

Open
@alejoforero

Description

@alejoforero

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

df = pd.DataFrame({'var1': ['44794724', None]})
df.to_csv('sample.csv', index=False)
df.head

df1 = pd.read_csv('sample.csv', dtype='string[pyarrow]',dtype_backend='pyarrow')
df2 = pd.read_csv('sample.csv', dtype='string[pyarrow]',dtype_backend='pyarrow',engine="pyarrow")

print(df1['var1'].astype(str).str.endswith('.0').sum())
print(df2['var1'].astype(str).str.endswith('.0').sum())

Issue Description

I've encountered an issue with read_csv when using the pyarrow engine. Specifically, when a numeric column with missing values is imported as a string type, each number in the column has ".0" appended to it. This issue occurs when setting the dtype to 'string' or 'string[pyarrow]'. The issue is not observed if at least one of the data rows contains a string, or if the dtype is set to 'object'.

Expected Behavior

Expected the same behavior turning on and off the pyarrow engine. The numeric values should be imported as strings without alteration.

Installed Versions

pandas '2.2.0' and '3.0.0.dev0+171.gd928a5cc22'
pyarrow=14.0.2
python=3.11.7
OS: win11-22H2

Metadata

Metadata

Assignees

Labels

Arrowpyarrow functionalityBugIO CSVread_csv, to_csv

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions