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 1 commit
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
10 changes: 9 additions & 1 deletion 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 All @@ -19,6 +18,7 @@
from pandas._libs.tslib import Timestamp
from pandas.errors import DtypeWarning, EmptyDataError, ParserError

import pandas as pd
from pandas import DataFrame, Index, MultiIndex, Series, compat, concat
import pandas.util.testing as tm

Expand Down Expand Up @@ -2160,6 +2160,14 @@ def test_suppress_error_output(all_parsers, capsys):
assert captured.err == ""


def test_err_msg_bytes():
# GH#29233
try:
pd.read_csv("nonexistent_name")
except FileNotFoundError as err:
assert err.strerror == "File nonexistent_name does not exist"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can pytest.raises not be used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea. i think this was split off from a branch where i was also checking err.errno

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also looks like theres another test i can merge this into



@pytest.mark.parametrize("filename", ["sé-es-vé.csv", "ru-sй.csv", "中文文件名.csv"])
def test_filename_with_special_chars(all_parsers, filename):
# see gh-15086.
Expand Down