Skip to content

Commit 665e4b1

Browse files
jbrockmendeljreback
authored andcommitted
ERR: stringify error message from parsers.pyx, closes #29233 (#30246)
1 parent be1c17d commit 665e4b1

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

pandas/_libs/parsers.pyx

+4-3
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ cdef class TextReader:
657657

658658
if isinstance(source, str):
659659
encoding = sys.getfilesystemencoding() or "utf-8"
660-
660+
usource = source
661661
source = source.encode(encoding)
662662

663663
if self.memory_map:
@@ -677,10 +677,11 @@ cdef class TextReader:
677677

678678
if ptr == NULL:
679679
if not os.path.exists(source):
680+
680681
raise FileNotFoundError(
681682
ENOENT,
682-
f'File {source} does not exist',
683-
source)
683+
f'File {usource} does not exist',
684+
usource)
684685
raise IOError('Initializing from file failed')
685686

686687
self.parser.source = ptr

pandas/tests/io/parser/test_common.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Tests that work on both the Python and C engines but do not have a
33
specific classification into the other test modules.
44
"""
5-
65
import codecs
76
from collections import OrderedDict
87
import csv
@@ -978,15 +977,15 @@ def test_path_local_path(all_parsers):
978977
def test_nonexistent_path(all_parsers):
979978
# gh-2428: pls no segfault
980979
# gh-14086: raise more helpful FileNotFoundError
980+
# GH#29233 "File foo" instead of "File b'foo'"
981981
parser = all_parsers
982982
path = "{}.csv".format(tm.rands(10))
983983

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

988988
filename = e.value.filename
989-
filename = filename.decode() if isinstance(filename, bytes) else filename
990989

991990
assert path == filename
992991

0 commit comments

Comments
 (0)