Skip to content

ERR: Clarify location of EOF on unbalanced quotes #22814

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
merged 1 commit into from
Sep 25, 2018
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
2 changes: 1 addition & 1 deletion pandas/_libs/src/parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ static int parser_handle_eof(parser_t *self) {
case IN_QUOTED_FIELD:
self->error_msg = (char *)malloc(bufsize);
snprintf(self->error_msg, bufsize,
"EOF inside string starting at line %lld",
"EOF inside string starting at row %lld",
(long long)self->file_lines);
return -1;

Expand Down
3 changes: 0 additions & 3 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2727,9 +2727,6 @@ def _next_iter_line(self, row_num):
'cannot be processed in Python\'s '
'native csv library at the moment, '
'so please pass in engine=\'c\' instead')
elif 'newline inside string' in msg:
msg = ('EOF inside string starting with '
'line ' + str(row_num))

if self.skipfooter > 0:
reason = ('Error could possibly be due to '
Expand Down
14 changes: 0 additions & 14 deletions pandas/tests/io/parser/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,6 @@ def test_malformed(self):
header=1, comment='#',
skipfooter=1)

def test_quoting(self):
bad_line_small = """printer\tresult\tvariant_name
Klosterdruckerei\tKlosterdruckerei <Salem> (1611-1804)\tMuller, Jacob
Klosterdruckerei\tKlosterdruckerei <Salem> (1611-1804)\tMuller, Jakob
Klosterdruckerei\tKlosterdruckerei <Kempten> (1609-1805)\t"Furststiftische Hofdruckerei, <Kempten""
Klosterdruckerei\tKlosterdruckerei <Kempten> (1609-1805)\tGaller, Alois
Klosterdruckerei\tKlosterdruckerei <Kempten> (1609-1805)\tHochfurstliche Buchhandlung <Kempten>""" # noqa
pytest.raises(Exception, self.read_table, StringIO(bad_line_small),
sep='\t')

good_line_small = bad_line_small + '"'
df = self.read_table(StringIO(good_line_small), sep='\t')
assert len(df) == 3

def test_unnamed_columns(self):
data = """A,B,C,,
1,2,3,4,5
Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/io/parser/quoting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pandas.util.testing as tm

from pandas import DataFrame
from pandas.errors import ParserError
from pandas.compat import PY3, StringIO, u


Expand Down Expand Up @@ -151,3 +152,19 @@ def test_quotechar_unicode(self):
if PY3:
result = self.read_csv(StringIO(data), quotechar=u('\u0001'))
tm.assert_frame_equal(result, expected)

def test_unbalanced_quoting(self):
# see gh-22789.
data = "a,b,c\n1,2,\"3"

if self.engine == "c":
regex = "EOF inside string starting at row 1"
else:
regex = "unexpected end of data"

with tm.assert_raises_regex(ParserError, regex):
self.read_csv(StringIO(data))

expected = DataFrame([[1, 2, 3]], columns=["a", "b", "c"])
data = self.read_csv(StringIO(data + '"'))
tm.assert_frame_equal(data, expected)