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: set errno in read_csv #13872

Closed
Murmuria opened this issue Aug 1, 2016 · 6 comments · Fixed by #41482
Closed

ERR: set errno in read_csv #13872

Murmuria opened this issue Aug 1, 2016 · 6 comments · Fixed by #41482
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@Murmuria
Copy link

Murmuria commented Aug 1, 2016

The same is true for Pandas on Python 2.7 with except IOError and on Python 3.5 with OSError. The following is how to reproduce the bug on Python 3.5.

Pandas is not reporting any errno within the exceptions. As a result, there is no way to differentiate between File Not Found Error (ENOENT) and other types of OSErrors.

Code Sample

try:
    pd.read_csv("dummy_file")
except OSError as e:
    print(e.errno, errno.ENOENT)

Current Output

(None, 2)

Expected Output

(2, 2)

output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Darwin
OS-release: 15.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.18.1
nose: 1.3.7
pip: 8.1.2
setuptools: 23.0.0
Cython: 0.24
numpy: 1.11.1
scipy: 0.17.1
statsmodels: 0.6.1
xarray: None
IPython: 4.2.0
sphinx: 1.4.1
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: 1.1.0
tables: 3.2.2
numexpr: 2.6.0
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.2
lxml: 3.6.0
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.40.0
pandas_datareader: None

@jreback
Copy link
Contributor

jreback commented Aug 1, 2016

I suppose. checking errno if quite non-pythonic. If you would like to submit a fix would take it though.

@jreback jreback added Error Reporting Incorrect or improved errors from pandas IO CSV read_csv, to_csv Difficulty Intermediate labels Aug 1, 2016
@jreback jreback added this to the Next Major Release milestone Aug 1, 2016
@jreback jreback changed the title Pandas' read_csv function does not report proper errno when raising OSError or IOError ERR: set errno in read_csv Aug 1, 2016
@jreback
Copy link
Contributor

jreback commented Aug 1, 2016

In [4]: pd.read_csv("dummy_file")
OSError: File b'dummy_file' does not exist

this is already a pretty useful error

@Murmuria
Copy link
Author

Murmuria commented Aug 1, 2016

Yes, the string error is fine. However, when you want to handle only the file does not exist error gracefully, and raise for all other errors, you always need to check the e.errno, something along these lines:

try:
    open("dummy_file")
except OSError as e:
    if e.errno != errno.ENOENT:  # errno.ENOENT = no such file or directory
    raise

@jreback
Copy link
Contributor

jreback commented Aug 1, 2016

its way more pythonic is to check for existence explicity then.
these errno's are a throwback to before exception checking.

as I said if you want to submit a patch, by all means.

@gfyoung
Copy link
Member

gfyoung commented Dec 8, 2016

@jreback : I agree with what you're saying about this and that error number isn't necessary without more justification. Would vote to close unless more info can be provided.

@mroeschke
Copy link
Member

This appears to work on master now. I suppose it could use a test

In [80]: import errno

In [81]: try:
    ...:     pd.read_csv("dummy_file")
    ...: except OSError as e:
    ...:     print(e.errno, errno.ENOENT)
    ...:
2 2

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed Error Reporting Incorrect or improved errors from pandas IO CSV read_csv, to_csv labels May 1, 2021
@mroeschke mroeschke modified the milestones: Contributions Welcome, 1.3 May 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
5 participants