Skip to content

EHN: Add filename to FileNotFoundError #24266

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
Jan 5, 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
5 changes: 4 additions & 1 deletion pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import time
import warnings

from csv import QUOTE_MINIMAL, QUOTE_NONNUMERIC, QUOTE_NONE
from errno import ENOENT

from libc.stdlib cimport free
from libc.string cimport strncpy, strlen, strcasecmp
Expand Down Expand Up @@ -696,7 +697,9 @@ cdef class TextReader:
if ptr == NULL:
if not os.path.exists(source):
raise compat.FileNotFoundError(
'File {source} does not exist'.format(source=source))
ENOENT,
'File {source} does not exist'.format(source=source),
source)
raise IOError('Initializing from file failed')

self.parser.source = ptr
Expand Down
8 changes: 7 additions & 1 deletion pandas/tests/io/parser/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,9 +898,15 @@ def test_nonexistent_path(all_parsers):

msg = ("does not exist" if parser.engine == "c"
else r"\[Errno 2\]")
with pytest.raises(compat.FileNotFoundError, match=msg):
with pytest.raises(compat.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


def test_missing_trailing_delimiters(all_parsers):
parser = all_parsers
Expand Down