Skip to content

BUG: encoding_errors=None with read_csv c-engine #45180

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 4 commits into from
Jan 4, 2022
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/v1.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ I/O
- Bug in :func:`read_csv` silently ignoring errors when failing to create a memory-mapped file (:issue:`44766`)
- Bug in :func:`read_csv` when passing a ``tempfile.SpooledTemporaryFile`` opened in binary mode (:issue:`44748`)
- Bug in :func:`read_json` raising ``ValueError`` when attempting to parse json strings containing "://" (:issue:`36271`)
- Bug in :func:`read_csv` when ``engine="c"`` and ``encoding_errors=None`` which caused a segfault (:issue:`45180`)
-

Period
Expand Down
2 changes: 2 additions & 0 deletions pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ cdef class TextReader:
# set encoding for native Python and C library
if isinstance(encoding_errors, str):
encoding_errors = encoding_errors.encode("utf-8")
elif encoding_errors is None:
encoding_errors = b"strict"
Py_INCREF(encoding_errors)
self.encoding_errors = PyBytes_AsString(encoding_errors)

Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/io/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,8 @@ def test_encoding_errors(encoding_errors, format):
bad_encoding = b"\xe4"

if format == "csv":
return
content = bad_encoding + b"\n" + bad_encoding
reader = pd.read_csv
content = b"," + bad_encoding + b"\n" + bad_encoding * 2 + b"," + bad_encoding
reader = partial(pd.read_csv, index_col=0)
else:
content = (
b'{"'
Expand Down