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

read_csv throws wrong exception on permissions issue #23784

Closed
omri374 opened this issue Nov 19, 2018 · 4 comments · Fixed by #32737
Closed

read_csv throws wrong exception on permissions issue #23784

omri374 opened this issue Nov 19, 2018 · 4 comments · Fixed by #32737
Assignees
Labels
Error Reporting Incorrect or improved errors from pandas IO CSV read_csv, to_csv
Milestone

Comments

@omri374
Copy link

omri374 commented Nov 19, 2018

Code Sample, a copy-pastable example if possible

# Your code here
train_df = pd.read_csv("../input/train.csv")

Problem description

When trying to open a CSV with no permissions on ubuntu 16.04, pandas returns this error:
OSError: Initializing from file failed

see this SO thread: https://stackoverflow.com/questions/50552404/oserror-initializing-from-file-failed-on-csv-in-pandas for an example.

Expected Output

Expected exception or details of exception should specify that this is a permission error, e.g. PermissionError and not OSError.

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]

INSTALLED VERSIONS

commit: None
python: 3.6.7.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-39-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.23.4
pytest: None
pip: 18.1
setuptools: 40.5.0
Cython: None
numpy: 1.15.4
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 7.1.1
sphinx: None
patsy: None
dateutil: 2.7.5
pytz: 2018.7
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@omri374 omri374 changed the title OSError: Initializing from file failed on csv throws wrong exception read_csv throws wrong exception on permissions issue Nov 19, 2018
@TomAugspurger
Copy link
Contributor

TomAugspurger commented Nov 19, 2018

What error does the standard library throw when you do open(path) on a file you don't have permissions on?

@omri374
Copy link
Author

omri374 commented Nov 20, 2018

open("../test/train.csv")

> PermissionError                           Traceback (most recent call last)
> <ipython-input-2-51df98a2583a> in <module>
> ----> 1 open("../test/train.csv")
> 
> PermissionError: [Errno 13] Permission denied: '../test/train.csv'
import pandas
pandas.read_csv("../test/train.csv")
> ---------------------------------------------------------------------------
> OSError                                   Traceback (most recent call last)
> <ipython-input-5-9d81e9f38383> in <module>
>       1 import pandas
> ----> 2 pandas.read_csv("../test/train.csv")
> 
> ~/anaconda3/envs/tf/lib/python3.6/site-packages/pandas/io/parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, doublequote, delim_whitespace, low_memory, memory_map, float_precision)
>     676                     skip_blank_lines=skip_blank_lines)
>     677 
> --> 678         return _read(filepath_or_buffer, kwds)
>     679 
>     680     parser_f.__name__ = name
> 
> ~/anaconda3/envs/tf/lib/python3.6/site-packages/pandas/io/parsers.py in _read(filepath_or_buffer, kwds)
>     438 
>     439     # Create the parser.
> --> 440     parser = TextFileReader(filepath_or_buffer, **kwds)
>     441 
>     442     if chunksize or iterator:
> 
> ~/anaconda3/envs/tf/lib/python3.6/site-packages/pandas/io/parsers.py in __init__(self, f, engine, **kwds)
>     785             self.options['has_index_names'] = kwds['has_index_names']
>     786 
> --> 787         self._make_engine(self.engine)
>     788 
>     789     def close(self):
> 
> ~/anaconda3/envs/tf/lib/python3.6/site-packages/pandas/io/parsers.py in _make_engine(self, engine)
>    1012     def _make_engine(self, engine='c'):
>    1013         if engine == 'c':
> -> 1014             self._engine = CParserWrapper(self.f, **self.options)
>    1015         else:
>    1016             if engine == 'python':
> 
> ~/anaconda3/envs/tf/lib/python3.6/site-packages/pandas/io/parsers.py in __init__(self, src, **kwds)
>    1706         kwds['usecols'] = self.usecols
>    1707 
> -> 1708         self._reader = parsers.TextReader(src, **kwds)
>    1709 
>    1710         passed_names = self.names is None
> 
> pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.__cinit__()
> 
> pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source()
> 
> OSError: Initializing from file failed

@TomAugspurger
Copy link
Contributor

Thanks. Are you interested in investigating how we should raise the same error?

@TomAugspurger TomAugspurger added IO Data IO issues that don't fit into a more specific label Error Reporting Incorrect or improved errors from pandas labels Nov 20, 2018
@TomAugspurger TomAugspurger added this to the Contributions Welcome milestone Nov 20, 2018
@jbrockmendel jbrockmendel added IO CSV read_csv, to_csv and removed IO Data IO issues that don't fit into a more specific label labels Dec 1, 2019
@roberthdevries
Copy link
Contributor

Take

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
No open projects
IO Method Robustness
Awaiting triage
Development

Successfully merging a pull request may close this issue.

5 participants