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

API: Raise FileNotFoundError in read_csv #14116

Merged

Conversation

gfyoung
Copy link
Member

@gfyoung gfyoung commented Aug 29, 2016

For a nonexistent file, raise the more specific FileNotFoundError for Python >= 3.3 in read_csv.

Closes #14086.

@codecov-io
Copy link

codecov-io commented Aug 29, 2016

Current coverage is 85.27% (diff: 66.66%)

Merging #14116 into master will increase coverage by <.01%

@@             master     #14116   diff @@
==========================================
  Files           139        139          
  Lines         50543      50545     +2   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          43101      43103     +2   
  Misses         7442       7442          
  Partials          0          0          

Powered by Codecov. Last update 8fdfa51...4923f73

@jorisvandenbossche
Copy link
Member

Looks good to me. Would be nice to also look if other readers raise IOError currently.

@jorisvandenbossche jorisvandenbossche added Error Reporting Incorrect or improved errors from pandas IO CSV read_csv, to_csv labels Aug 29, 2016
@gfyoung gfyoung force-pushed the filenotfound-compat branch 2 times, most recently from f3dcf40 to a485594 Compare August 30, 2016 02:06
@gfyoung
Copy link
Member Author

gfyoung commented Aug 30, 2016

@jorisvandenbossche : read_hdf is another one that could raise a better error. 😄

@jreback
Copy link
Contributor

jreback commented Aug 31, 2016

I think this also exists for json / excel.

@gfyoung
Copy link
Member Author

gfyoung commented Aug 31, 2016

@jreback : They give different errors, at least when I tried locally.

@jreback
Copy link
Contributor

jreback commented Aug 31, 2016

@gfyoung can you elaborate?

@gfyoung
Copy link
Member Author

gfyoung commented Aug 31, 2016

@jreback : Sorry, wasn't clear. read_excel raises FileNotFoundError already (it calls Python's open function to open the file). With read_json, I get this:

>>> read_json('nonexistent.json')
...
ValueError: Unexpected character found when decoding 'null'

I suppose that could be improved but seems a little different from what I'm fixing here.

@jreback
Copy link
Contributor

jreback commented Aug 31, 2016

ok, yes this should be ok for all other things. can you quickly see if read_stat/read_sas are ok? (I think things that call io/common/_get_filepath_or_buffer are fine. read_csv/read_hdf just do special things.

ping if ok

@jreback jreback added this to the 0.19.0 milestone Aug 31, 2016
@@ -439,6 +439,7 @@ API changes
- ``Timestamp.to_pydatetime`` will issue a ``UserWarning`` when ``warn=True``, and the instance has a non-zero number of nanoseconds (:issue:`14101`)
- ``Panel.to_sparse`` will raise a ``NotImplementedError`` exception when called (:issue:`13778`)
- ``Index.reshape`` will raise a ``NotImplementedError`` exception when called (:issue:`12882`)
- ``pd.read_csv()``, ``pd.read_table()``, and ``pd.read_hdf()`` raise a ``FileNotFoundError`` exception for Python >= 3.3 when called on a nonexistent file (:issue:`14086`)
Copy link
Contributor

Choose a reason for hiding this comment

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

update this to say that this is the standard for file not found and is back-compat to OSError.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, done.

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.
@gfyoung gfyoung force-pushed the filenotfound-compat branch from a485594 to 4923f73 Compare September 1, 2016 02:35
@jorisvandenbossche
Copy link
Member

Looks good to me!

@gfyoung
Copy link
Member Author

gfyoung commented Sep 1, 2016

@jreback : Travis is passing. Ready to merge if there are no other concerns.

@jorisvandenbossche jorisvandenbossche merged commit 58199c5 into pandas-dev:master Sep 1, 2016
@gfyoung gfyoung deleted the filenotfound-compat branch September 1, 2016 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas IO CSV read_csv, to_csv
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants