Skip to content
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

ERR: in python >= 3.5 use FileNotFoundError instead of OSError #14086

Closed
brunobeltran opened this issue Aug 25, 2016 · 4 comments
Closed

ERR: in python >= 3.5 use FileNotFoundError instead of OSError #14086

brunobeltran opened this issue Aug 25, 2016 · 4 comments
Labels
Enhancement Error Reporting Incorrect or improved errors from pandas IO CSV read_csv, to_csv
Milestone

Comments

@brunobeltran
Copy link

brunobeltran commented Aug 25, 2016

Simple to reproduce:

import pandas as pd
try:
    pd.read_csv('this_file_does_not_exist.csv')
except FileNotFoundError:
    print('This should execute.')

Instead, I get an OSError, which tells me in text that OSError: File b'this_file_does_not_exist.csv' does not exist.

https://docs.python.org/3.5/library/exceptions.html seems to suggest that OSError now has various subclasses, e.g. FileNotFoundError, for specific errors such as this one.

Output of pd.show_versions():

INSTALLED VERSIONS
------------------
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-31-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8

pandas: 0.18.1
nose: None
pip: 8.1.2
setuptools: 23.0.0
Cython: None
numpy: 1.11.1
scipy: 0.18.0
statsmodels: None
xarray: None
IPython: 5.0.0
sphinx: None
patsy: None
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None
@jreback
Copy link
Contributor

jreback commented Aug 25, 2016

FYI your syntax is non-python

try/except is the idiom

sure, this could be enable for >= 3.5. would have to be compat for < 3.5 (continue to raise IOError). These both subclass OSError so would be ok. pull-requests are welcome.

compat code should go in pandas/compat/__init__.py

This change would also should be make across the entire io suite. E.g. json, hdf, excel, anything that can read from files.

@jreback jreback added Enhancement Difficulty Novice Error Reporting Incorrect or improved errors from pandas IO CSV read_csv, to_csv labels Aug 25, 2016
@jreback jreback added this to the Next Major Release milestone Aug 25, 2016
@jreback jreback changed the title pd.read_csv throws OSError instead of FileNotFoundError ERR: in python >= 3.5 use FileNotFoundError instead of OSError Aug 25, 2016
@brunobeltran
Copy link
Author

brunobeltran commented Aug 25, 2016

Edited original comment to fix typo you pointed out. Switching between languages is a pain. I agree with you proposed solution. Thanks for the pointers!

@jreback
Copy link
Contributor

jreback commented Aug 25, 2016

@brunobeltran hah, no problem. easy solution to switching. just always use python! lol

@gfyoung
Copy link
Member

gfyoung commented Aug 29, 2016

@jreback : IOError does not sub-class OSError in Python 2.x FYI, but the compat point still stands. In Python 3.x, IOError is aliased to OSError.

@jreback jreback modified the milestones: 0.19.0, Next Major Release Aug 31, 2016
gfyoung added a commit to forking-repos/pandas that referenced this issue Sep 1, 2016
For a nonexistent file, raise the more specific
FileNotFoundError for Python >= 3.3 in read_csv,
read_table, and read_hdf.

This error is backported to Python 2.x as IOError.

Closes pandas-devgh-14086.
jorisvandenbossche pushed a commit that referenced this issue Sep 1, 2016
For a nonexistent file, raise the more specific
FileNotFoundError for Python >= 3.3 in read_csv,
read_table, and read_hdf.

This error is backported to Python 2.x as IOError.

Closes gh-14086.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Error Reporting Incorrect or improved errors from pandas IO CSV read_csv, to_csv
Projects
None yet
Development

No branches or pull requests

3 participants