Skip to content

ERR: Disallow multi-char quotechar for C engine #15050

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ Other API Changes
- ``DataFrame.applymap()`` with an empty ``DataFrame`` will return a copy of the empty ``DataFrame`` instead of a ``Series`` (:issue:`8222`)

- ``pd.read_csv()`` will now issue a ``ParserWarning`` whenever there are conflicting values provided by the ``dialect`` parameter and the user (:issue:`14898`)
- ``pd.read_csv()`` will now raise a ``ValueError`` for the C engine if the quote character is larger than than one byte (:issue:`11592`)

.. _whatsnew_0200.deprecations:

Expand Down
11 changes: 11 additions & 0 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,17 @@ def _clean_options(self, options, engine):
encoding=encoding)
engine = 'python'

quotechar = options['quotechar']
if (quotechar is not None and
isinstance(quotechar, (str, compat.text_type, bytes))):
if (len(quotechar) == 1 and ord(quotechar) > 127 and
engine not in ('python', 'python-fwf')):
fallback_reason = ("ord(quotechar) > 127, meaning the "
"quotechar is larger than one byte, "
"and the 'c' engine does not support "
"such quotechars")
engine = 'python'

if fallback_reason and engine_specified:
raise ValueError(fallback_reason)

Expand Down
2 changes: 1 addition & 1 deletion pandas/io/tests/parser/quoting.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,5 @@ def test_quotechar_unicode(self):

# Compared to Python 3.x, Python 2.x does not handle unicode well.
if PY3:
result = self.read_csv(StringIO(data), quotechar=u('\u0394'))
result = self.read_csv(StringIO(data), quotechar=u('\u0001'))
tm.assert_frame_equal(result, expected)
4 changes: 4 additions & 0 deletions pandas/io/tests/parser/test_unsupported.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ def test_c_engine(self):
sep=None, delim_whitespace=False)
with tm.assertRaisesRegexp(ValueError, msg):
read_table(StringIO(data), engine='c', sep=r'\s')
with tm.assertRaisesRegexp(ValueError, msg):
read_table(StringIO(data), engine='c', quotechar=chr(128))
with tm.assertRaisesRegexp(ValueError, msg):
read_table(StringIO(data), engine='c', skipfooter=1)

# specify C-unsupported options without python-unsupported options
with tm.assert_produces_warning(parsers.ParserWarning):
read_table(StringIO(data), sep=None, delim_whitespace=False)
with tm.assert_produces_warning(parsers.ParserWarning):
read_table(StringIO(data), quotechar=chr(128))
with tm.assert_produces_warning(parsers.ParserWarning):
read_table(StringIO(data), sep=r'\s')
with tm.assert_produces_warning(parsers.ParserWarning):
Expand Down