Skip to content

ERR: stringify error message from parsers.pyx, closes #29233 #30246

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 3 commits into from
Dec 13, 2019
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
7 changes: 4 additions & 3 deletions pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ cdef class TextReader:

if isinstance(source, str):
encoding = sys.getfilesystemencoding() or "utf-8"

usource = source
source = source.encode(encoding)

if self.memory_map:
Expand All @@ -677,10 +677,11 @@ cdef class TextReader:

if ptr == NULL:
if not os.path.exists(source):

raise FileNotFoundError(
ENOENT,
f'File {source} does not exist',
source)
f'File {usource} does not exist',
usource)
raise IOError('Initializing from file failed')

self.parser.source = ptr
Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/io/parser/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Tests that work on both the Python and C engines but do not have a
specific classification into the other test modules.
"""

import codecs
from collections import OrderedDict
import csv
Expand Down Expand Up @@ -978,15 +977,15 @@ def test_path_local_path(all_parsers):
def test_nonexistent_path(all_parsers):
# gh-2428: pls no segfault
# gh-14086: raise more helpful FileNotFoundError
# GH#29233 "File foo" instead of "File b'foo'"
parser = all_parsers
path = "{}.csv".format(tm.rands(10))

msg = "does not exist" if parser.engine == "c" else r"\[Errno 2\]"
msg = f"File {path} does not exist" if parser.engine == "c" else r"\[Errno 2\]"
with pytest.raises(FileNotFoundError, match=msg) as e:
parser.read_csv(path)

filename = e.value.filename
filename = filename.decode() if isinstance(filename, bytes) else filename

assert path == filename

Expand Down