Skip to content

Commit a3d7433

Browse files
milliamsPingviinituutti
authored andcommitted
EHN: Add filename to FileNotFoundError (pandas-dev#24266)
1 parent 85e97a0 commit a3d7433

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

pandas/_libs/parsers.pyx

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import time
66
import warnings
77

88
from csv import QUOTE_MINIMAL, QUOTE_NONNUMERIC, QUOTE_NONE
9+
from errno import ENOENT
910

1011
from libc.stdlib cimport free
1112
from libc.string cimport strncpy, strlen, strcasecmp
@@ -696,7 +697,9 @@ cdef class TextReader:
696697
if ptr == NULL:
697698
if not os.path.exists(source):
698699
raise compat.FileNotFoundError(
699-
'File {source} does not exist'.format(source=source))
700+
ENOENT,
701+
'File {source} does not exist'.format(source=source),
702+
source)
700703
raise IOError('Initializing from file failed')
701704

702705
self.parser.source = ptr

pandas/tests/io/parser/test_common.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -898,9 +898,15 @@ def test_nonexistent_path(all_parsers):
898898

899899
msg = ("does not exist" if parser.engine == "c"
900900
else r"\[Errno 2\]")
901-
with pytest.raises(compat.FileNotFoundError, match=msg):
901+
with pytest.raises(compat.FileNotFoundError, match=msg) as e:
902902
parser.read_csv(path)
903903

904+
filename = e.value.filename
905+
filename = filename.decode() if isinstance(
906+
filename, bytes) else filename
907+
908+
assert path == filename
909+
904910

905911
def test_missing_trailing_delimiters(all_parsers):
906912
parser = all_parsers

0 commit comments

Comments
 (0)