Skip to content

Commit 19f626a

Browse files
committed
API: Rename CParserError to ParserError.
Closes pandas-devgh-12665.
1 parent 233d51d commit 19f626a

File tree

10 files changed

+25
-25
lines changed

10 files changed

+25
-25
lines changed

doc/source/io.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1165,8 +1165,8 @@ too many will cause an error by default:
11651165
11661166
In [28]: pd.read_csv(StringIO(data))
11671167
---------------------------------------------------------------------------
1168-
CParserError Traceback (most recent call last)
1169-
CParserError: Error tokenizing data. C error: Expected 3 fields in line 3, saw 4
1168+
ParserError Traceback (most recent call last)
1169+
ParserError: Error tokenizing data. C error: Expected 3 fields in line 3, saw 4
11701170
11711171
You can elect to skip bad lines:
11721172

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Backwards incompatible API changes
4141
.. _whatsnew_0200.api:
4242

4343

44+
- ``CParserError`` has been renamed to ``ParserError`` in ``pd.read_csv`` (:issue:`12665`)
4445

4546

4647

pandas/io/common.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ def urlopen(*args, **kwargs):
6565
_VALID_URLS.discard('')
6666

6767

68-
class CParserError(ValueError):
68+
class ParserError(ValueError):
6969
"""
70-
Exception that is thrown by the C engine when it encounters
71-
a parsing error in `pd.read_csv`
70+
Exception that is thrown by an error is encountered in `pd.read_csv`
7271
"""
7372
pass
7473

pandas/io/parsers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from pandas.io.date_converters import generic_parser
2727
from pandas.io.common import (get_filepath_or_buffer, _validate_header_arg,
2828
_get_handle, UnicodeReader, UTF8Recoder,
29-
BaseIterator, CParserError, EmptyDataError,
29+
BaseIterator, ParserError, EmptyDataError,
3030
ParserWarning, _NA_VALUES)
3131
from pandas.tseries import tools
3232

@@ -1141,7 +1141,7 @@ def tostr(x):
11411141
# long
11421142
for n in range(len(columns[0])):
11431143
if all(['Unnamed' in tostr(c[n]) for c in columns]):
1144-
raise CParserError(
1144+
raise ParserError(
11451145
"Passed header=[%s] are too many rows for this "
11461146
"multi_index of columns"
11471147
% ','.join([str(x) for x in self.header])

pandas/io/tests/parser/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_bad_stream_exception(self):
5050
# Issue 13652:
5151
# This test validates that both python engine
5252
# and C engine will raise UnicodeDecodeError instead of
53-
# c engine raising CParserError and swallowing exception
53+
# c engine raising ParserError and swallowing exception
5454
# that caused read to fail.
5555
handle = open(self.csv_shiftjs, "rb")
5656
codec = codecs.lookup("utf-8")

pandas/io/tests/parser/test_textreader.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def test_skip_bad_lines(self):
154154

155155
reader = TextReader(StringIO(data), delimiter=':',
156156
header=None)
157-
self.assertRaises(parser.CParserError, reader.read)
157+
self.assertRaises(parser.ParserError, reader.read)
158158

159159
reader = TextReader(StringIO(data), delimiter=':',
160160
header=None,
@@ -197,7 +197,7 @@ def test_header_not_enough_lines(self):
197197
assert_array_dicts_equal(expected, recs)
198198

199199
# not enough rows
200-
self.assertRaises(parser.CParserError, TextReader, StringIO(data),
200+
self.assertRaises(parser.ParserError, TextReader, StringIO(data),
201201
delimiter=',', header=5, as_recarray=True)
202202

203203
def test_header_not_enough_lines_as_recarray(self):
@@ -218,7 +218,7 @@ def test_header_not_enough_lines_as_recarray(self):
218218
assert_array_dicts_equal(expected, recs)
219219

220220
# not enough rows
221-
self.assertRaises(parser.CParserError, TextReader, StringIO(data),
221+
self.assertRaises(parser.ParserError, TextReader, StringIO(data),
222222
delimiter=',', header=5, as_recarray=True)
223223

224224
def test_escapechar(self):

pandas/io/tests/parser/test_unsupported.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import pandas.util.testing as tm
1616

1717
from pandas.compat import StringIO
18-
from pandas.io.common import CParserError
18+
from pandas.io.common import ParserError
1919
from pandas.io.parsers import read_csv, read_table
2020

2121

@@ -78,9 +78,9 @@ def test_c_engine(self):
7878
x q 30 3 -0.6662 -0.5243 -0.3580 0.89145 2.5838"""
7979
msg = 'Error tokenizing data'
8080

81-
with tm.assertRaisesRegexp(CParserError, msg):
81+
with tm.assertRaisesRegexp(ParserError, msg):
8282
read_table(StringIO(text), sep='\s+')
83-
with tm.assertRaisesRegexp(CParserError, msg):
83+
with tm.assertRaisesRegexp(ParserError, msg):
8484
read_table(StringIO(text), engine='c', sep='\s+')
8585

8686
msg = "Only length-1 thousands markers supported"

pandas/io/tests/test_html.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
is_platform_windows)
2424
from pandas.io.common import URLError, urlopen, file_path_to_url
2525
from pandas.io.html import read_html
26-
from pandas.parser import CParserError
26+
from pandas.parser import ParserError
2727

2828
import pandas.util.testing as tm
2929
from pandas.util.testing import makeCustomDataframe as mkdf, network
@@ -652,7 +652,7 @@ def test_parse_dates_combine(self):
652652

653653
def test_computer_sales_page(self):
654654
data = os.path.join(DATA_PATH, 'computer_sales_page.html')
655-
with tm.assertRaisesRegexp(CParserError, r"Passed header=\[0,1\] are "
655+
with tm.assertRaisesRegexp(ParserError, r"Passed header=\[0,1\] are "
656656
"too many rows for this multi_index "
657657
"of columns"):
658658
self.read_html(data, header=[0, 1])

pandas/parser.pyx

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ from cpython cimport (PyObject, PyBytes_FromString,
1313
PyUnicode_Check, PyUnicode_AsUTF8String,
1414
PyErr_Occurred, PyErr_Fetch)
1515
from cpython.ref cimport PyObject, Py_XDECREF
16-
from io.common import CParserError, DtypeWarning, EmptyDataError
16+
from io.common import ParserError, DtypeWarning, EmptyDataError
1717

1818

1919
cdef extern from "Python.h":
@@ -719,7 +719,7 @@ cdef class TextReader:
719719
if isinstance(msg, list):
720720
msg = "[%s], len of %d," % (
721721
','.join([ str(m) for m in msg ]), len(msg))
722-
raise CParserError(
722+
raise ParserError(
723723
'Passed header=%s but only %d lines in file'
724724
% (msg, self.parser.lines))
725725

@@ -812,7 +812,7 @@ cdef class TextReader:
812812
passed_count = len(header[0])
813813

814814
# if passed_count > field_count:
815-
# raise CParserError('Column names have %d fields, '
815+
# raise ParserError('Column names have %d fields, '
816816
# 'data has %d fields'
817817
# % (passed_count, field_count))
818818

@@ -1004,7 +1004,7 @@ cdef class TextReader:
10041004
(num_cols >= self.parser.line_fields[i]) * num_cols
10051005

10061006
if self.table_width - self.leading_cols > num_cols:
1007-
raise CParserError(
1007+
raise ParserError(
10081008
"Too many columns specified: expected %s and found %s" %
10091009
(self.table_width - self.leading_cols, num_cols))
10101010

@@ -1059,7 +1059,7 @@ cdef class TextReader:
10591059
self.use_unsigned)
10601060

10611061
if col_res is None:
1062-
raise CParserError('Unable to parse column %d' % i)
1062+
raise ParserError('Unable to parse column %d' % i)
10631063

10641064
results[i] = col_res
10651065

@@ -1310,7 +1310,7 @@ def _is_file_like(obj):
13101310
if PY3:
13111311
import io
13121312
if isinstance(obj, io.TextIOWrapper):
1313-
raise CParserError('Cannot handle open unicode files (yet)')
1313+
raise ParserError('Cannot handle open unicode files (yet)')
13141314

13151315
# BufferedReader is a byte reader for Python 3
13161316
file = io.BufferedReader
@@ -2015,7 +2015,7 @@ cdef raise_parser_error(object base, parser_t *parser):
20152015
else:
20162016
message += 'no error message set'
20172017

2018-
raise CParserError(message)
2018+
raise ParserError(message)
20192019

20202020

20212021
def _concatenate_chunks(list chunks):

pandas/tests/frame/test_to_csv.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import numpy as np
99

1010
from pandas.compat import (lmap, range, lrange, StringIO, u)
11-
from pandas.parser import CParserError
11+
from pandas.parser import ParserError
1212
from pandas import (DataFrame, Index, Series, MultiIndex, Timestamp,
1313
date_range, read_csv, compat, to_datetime)
1414
import pandas as pd
@@ -589,7 +589,7 @@ def _make_frame(names=None):
589589

590590
for i in [5, 6, 7]:
591591
msg = 'len of {i}, but only 5 lines in file'.format(i=i)
592-
with assertRaisesRegexp(CParserError, msg):
592+
with assertRaisesRegexp(ParserError, msg):
593593
read_csv(path, tupleize_cols=False,
594594
header=lrange(i), index_col=0)
595595

0 commit comments

Comments
 (0)