Skip to content

Commit

Permalink
Fix unbound local with bad engine (#16511)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtratner authored and jreback committed May 31, 2017
1 parent d4f80b0 commit 9b0ea41
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/source/whatsnew/v0.20.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Bug Fixes
detecting the terminal size. This fix only applies to python 3 (:issue:`16496`)
- Bug in using ``pathlib.Path`` or ``py.path.local`` objects with io functions (:issue:`16291`)
- Bug in ``DataFrame.update()`` with ``overwrite=False`` and ``NaN values`` (:issue:`15593`)
- Passing an invalid engine to :func:`read_csv` now raises an informative
``ValueError`` rather than ``UnboundLocalError``. (:issue:`16511`)




Expand Down
4 changes: 4 additions & 0 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,10 @@ def _make_engine(self, engine='c'):
klass = PythonParser
elif engine == 'python-fwf':
klass = FixedWidthFieldParser
else:
raise ValueError('Unknown engine: {engine} (valid options are'
' "c", "python", or' ' "python-fwf")'.format(
engine=engine))
self._engine = klass(self.f, **self.options)

def _failover_to_python(self):
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/io/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,10 @@ def test_next(self):
assert next_line.strip() == line.strip()

pytest.raises(StopIteration, next, wrapper)

def test_unknown_engine(self):
with tm.ensure_clean() as path:
df = tm.makeDataFrame()
df.to_csv(path)
with tm.assert_raises_regex(ValueError, 'Unknown engine'):
read_csv(path, engine='pyt')

0 comments on commit 9b0ea41

Please sign in to comment.