Skip to content

BUG: read_csv na_values parameters not working with pyarrow engine. #53137

@Happily-Coding

Description

@Happily-Coding

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

# Since na_values parameter is set, '-' and '?' should be interpreted as na values, but aren't.
df_with_pyarrow_engine = pd.read_csv(
    'https://gist.githubusercontent.com/ycui1/dd33483219aeec871b9137a1e7925235/raw/6ae3e4e51b4807313068244dd315eb5e0a989827/pandas_missing_values_dataset.csv',
    engine='pyarrow',
    dtype_backend='pyarrow',
    na_values=['-','?'])

print(df_with_pyarrow_engine.head(5))

Issue Description

When using engine='pyarrow' & na_values at the same time, on pandas read_csv method, additional na_values will not be detected correctly.

Expected Behavior

import pandas as pd

# Since na_values parameter is set, '-' and '?' will be interpreted as na values.
df_without_pyarrow_engine = pd.read_csv(
    'https://gist.githubusercontent.com/ycui1/dd33483219aeec871b9137a1e7925235/raw/6ae3e4e51b4807313068244dd315eb5e0a989827/pandas_missing_values_dataset.csv',
    #engine='pyarrow',
    dtype_backend='pyarrow',
    na_values=['-','?'])

print(df_without_pyarrow_engine.head(5))

Installed Versions

INSTALLED VERSIONS

commit : 37ea63d
python : 3.11.2.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : AMD64 Family 23 Model 113 Stepping 0, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Spanish_Argentina.1252

pandas : 2.0.1
numpy : 1.23.5
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 65.5.0
pip : 23.1.2
Cython : None
pytest : None
hypothesis : None
sphinx : 6.1.3
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.11.0
pandas_datareader: None
bs4 : 4.11.2
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2023.4.0
gcsfs : None
matplotlib : 3.7.1
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 12.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : 2.3.0
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Arrowpyarrow functionalityBugClosing CandidateMay be closeable, needs more eyeballsIO CSVread_csv, to_csv

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions