Skip to content
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

BUG: read_csv with engine='pyarrow' ignores quotechar option #52266

Closed
3 tasks done
grantslatton opened this issue Mar 29, 2023 · 3 comments · Fixed by #56352
Closed
3 tasks done

BUG: read_csv with engine='pyarrow' ignores quotechar option #52266

grantslatton opened this issue Mar 29, 2023 · 3 comments · Fixed by #56352
Assignees
Labels
Arrow pyarrow functionality Bug IO CSV read_csv, to_csv

Comments

@grantslatton
Copy link

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
from io import StringIO

csv = '''example,header
'comma , here',foobar'''

pd.read_csv(StringIO(csv), sep=',', quotechar="'")
'''
Correct output

        example  header
0  comma , here  foobar
'''

pd.read_csv(StringIO(csv), sep=',', quotechar="'", engine='pyarrow')

'''
Error output:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/lib/python3.10/site-packages/pandas/util/_decorators.py", line 211, in wrapper
    return func(*args, **kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/pandas/util/_decorators.py", line 331, in wrapper
    return func(*args, **kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/pandas/io/parsers/readers.py", line 950, in read_csv
    return _read(filepath_or_buffer, kwds)
  File "/opt/homebrew/lib/python3.10/site-packages/pandas/io/parsers/readers.py", line 611, in _read
    return parser.read(nrows)
  File "/opt/homebrew/lib/python3.10/site-packages/pandas/io/parsers/readers.py", line 1766, in read
    df = self._engine.read()  # type: ignore[attr-defined]
  File "/opt/homebrew/lib/python3.10/site-packages/pandas/io/parsers/arrow_parser_wrapper.py", line 147, in read
    table = pyarrow_csv.read_csv(
  File "pyarrow/_csv.pyx", line 1217, in pyarrow._csv.read_csv
  File "pyarrow/_csv.pyx", line 1226, in pyarrow._csv.read_csv
  File "pyarrow/error.pxi", line 144, in pyarrow.lib.pyarrow_internal_check_status
  File "pyarrow/error.pxi", line 100, in pyarrow.lib.check_status
pyarrow.lib.ArrowInvalid: CSV parse error: Expected 2 columns, got 3: 'comma , here',foobar
'''

Issue Description

It appears quotechar is getting ignored. It works if it's double quotes (the default) but no other quote type.

Expected Behavior

Expected the parse to work (and be the same as non-pyarrow pandas).

I believe the bug is in this bit of code: https://github.com/pandas-dev/pandas/blob/main/pandas/io/parsers/arrow_parser_wrapper.py#L52

Specifically, the pyarrow csv parser seems to want quote_char and pandas is giving quotechar, so this mapping probably needs updated. I have not tested this, though.

Installed Versions

INSTALLED VERSIONS

commit : 2e218d1
python : 3.10.10.final.0
python-bits : 64
OS : Darwin
OS-release : 21.6.0
Version : Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:35 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T8101
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.3
numpy : 1.23.3
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 67.2.0
pip : 23.0
Cython : 0.29.32
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.1
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2022.11.0
gcsfs : None
matplotlib : 3.6.2
numba : 0.56.4
numexpr : None
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.9.3
snappy : None
sqlalchemy : 1.4.45
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
xlwt : None
zstandard : 0.20.0
tzdata : 2022.5

@grantslatton grantslatton added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 29, 2023
@amyhxy
Copy link

amyhxy commented Mar 29, 2023

take

@rhshadrach rhshadrach added IO CSV read_csv, to_csv Arrow pyarrow functionality labels Mar 29, 2023
@lithomas1 lithomas1 removed the Needs Triage Issue that has not been reviewed by a pandas team member label Mar 29, 2023
@chetanpatel2510
Copy link

Hi @amyhxy
Any luck on this? I am also facing the same issue.

@vd1
Copy link

vd1 commented Apr 28, 2024

I have a very similar problem.
My toy file is:

1 ,2 , "[3,4]"
6 ,3 , "[7,5]"
df = pd.read_csv(
    file_path,
    engine='python', 
    quotechar='"',
    delimiter=','
)

reads it with no problem. But if I use

parse_options = pyarrow.csv.ParseOptions(
    delimiter=',',
    quote_char='"',
)
pyarrow.csv.read_csv(file_path, parse_options=parse_options)

I get an error:

pyarrow.lib.ArrowInvalid: CSV parse error: Expected 3 columns, got 4: 1 ,2 , "[3,4]"

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 a pull request may close this issue.

6 participants