Skip to content

Commit cbefe18

Browse files
authored
BUG: encoding_errors=None with read_csv c-engine (#45180)
1 parent d06fb91 commit cbefe18

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

doc/source/whatsnew/v1.4.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ I/O
881881
- Bug in :func:`read_csv` silently ignoring errors when failing to create a memory-mapped file (:issue:`44766`)
882882
- Bug in :func:`read_csv` when passing a ``tempfile.SpooledTemporaryFile`` opened in binary mode (:issue:`44748`)
883883
- Bug in :func:`read_json` raising ``ValueError`` when attempting to parse json strings containing "://" (:issue:`36271`)
884+
- Bug in :func:`read_csv` when ``engine="c"`` and ``encoding_errors=None`` which caused a segfault (:issue:`45180`)
884885
-
885886

886887
Period

pandas/_libs/parsers.pyx

+2
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ cdef class TextReader:
375375
# set encoding for native Python and C library
376376
if isinstance(encoding_errors, str):
377377
encoding_errors = encoding_errors.encode("utf-8")
378+
elif encoding_errors is None:
379+
encoding_errors = b"strict"
378380
Py_INCREF(encoding_errors)
379381
self.encoding_errors = PyBytes_AsString(encoding_errors)
380382

pandas/tests/io/test_common.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,8 @@ def test_encoding_errors(encoding_errors, format):
555555
bad_encoding = b"\xe4"
556556

557557
if format == "csv":
558-
return
559-
content = bad_encoding + b"\n" + bad_encoding
560-
reader = pd.read_csv
558+
content = b"," + bad_encoding + b"\n" + bad_encoding * 2 + b"," + bad_encoding
559+
reader = partial(pd.read_csv, index_col=0)
561560
else:
562561
content = (
563562
b'{"'

0 commit comments

Comments
 (0)