Fix unbound local with bad engine
State: closed

This was so small I figured simpler to put up a PR rather than issue then PR. :)

Previously, passing a bad engine to read_csv gave an less-than-informative UnboundLocalError:

```
Traceback (most recent call last):
  File "example_test.py", line 9, in <module>
    pd.read_csv(tfp.name, engine='pyt')
  File "/Users/jtratner/pandas/pandas/io/parsers.py", line 655, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "/Users/jtratner/pandas/pandas/io/parsers.py", line 405, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "/Users/jtratner/pandas/pandas/io/parsers.py", line 762, in __init__
    self._make_engine(self.engine)
  File "/Users/jtratner/pandas/pandas/io/parsers.py", line 972, in _make_engine
    self._engine = klass(self.f, **self.options)
UnboundLocalError: local variable 'klass' referenced before assignment
```

Now it gives a much nicer ValueError:

```
Traceback (most recent call last):
  File "example_test.py", line 9, in <module>
    pd.read_csv(fp, engine='pyt')
  File "/Users/jtratner/pandas/pandas/io/parsers.py", line 655, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "/Users/jtratner/pandas/pandas/io/parsers.py", line 405, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "/Users/jtratner/pandas/pandas/io/parsers.py", line 762, in __init__
    self._make_engine(self.engine)
  File "/Users/jtratner/pandas/pandas/io/parsers.py", line 974, in _make_engine
    ' or "python-fwf")' % engine)
ValueError: Unknown engine: 'pyt' (valid are "c", "python", or "python-fwf")
```

 - [x] tests added / passed - added test that correct ValueError is generated
 - [x] passes ``git diff upstream/master --name-only -- '*.py' | flake8 --diff``
 - [x] whatsnew entry

I was not sure where to stick the test or the whatsnew entry (or if a whatsnew entry is really necessary), so please tell me if I should move it elsewhere.

Cheers!

Labels:
name: Error Reporting
description: Incorrect or improved errors from pandas
name: IO CSV
description: read_csv, to_csv

Comments:
(or if you want to do this a totally different way / different error I can make changes or close)
made all the requested changes - thanks for the review @jreback !
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=h1) Report
> Merging [#16511](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/b0d9ee0b4c0911e089d4dd7c6a676557909fb7da?src=pr&el=desc) will **decrease** coverage by `0.36%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/16511/graphs/tree.svg?token=eZ4WkYLtcO&src=pr&height=150&width=650)](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #16511      +/-   ##
==========================================
- Coverage   90.79%   90.43%   -0.37%     
==========================================
  Files         161      161              
  Lines       51063    51046      -17     
==========================================
- Hits        46363    46162     -201     
- Misses       4700     4884     +184
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.27% <100%> (-0.37%)` | :arrow_down: |
| #single | `40.16% <0%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/parsers.py](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhcnNlcnMucHk=) | `95.33% <100%> (-0.33%)` | :arrow_down: |
| [pandas/io/formats/excel.py](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZXhjZWwucHk=) | `74.24% <0%> (-22.41%)` | :arrow_down: |
| [pandas/io/excel.py](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=tree#diff-cGFuZGFzL2lvL2V4Y2VsLnB5) | `62.31% <0%> (-18.33%)` | :arrow_down: |
| [pandas/conftest.py](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=tree#diff-cGFuZGFzL2NvbmZ0ZXN0LnB5) | `95.83% <0%> (-0.6%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `80.79% <0%> (-0.2%)` | :arrow_down: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `94.71% <0%> (-0.19%)` | :arrow_down: |
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `92.16% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/resample.py](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzYW1wbGUucHk=) | `96.08% <0%> (-0.02%)` | :arrow_down: |
| [pandas/core/reshape/pivot.py](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9waXZvdC5weQ==) | `95.08% <0%> (ø)` | :arrow_up: |
| ... and [4 more](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=footer). Last update [b0d9ee0...26a3300](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=h1) Report
> Merging [#16511](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/b0d9ee0b4c0911e089d4dd7c6a676557909fb7da?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/16511/graphs/tree.svg?src=pr&token=eZ4WkYLtcO&width=650&height=150)](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #16511      +/-   ##
==========================================
+ Coverage   90.79%   90.79%   +<.01%     
==========================================
  Files         161      161              
  Lines       51063    51064       +1     
==========================================
+ Hits        46363    46366       +3     
+ Misses       4700     4698       -2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.63% <100%> (ø)` | :arrow_up: |
| #single | `40.15% <0%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/parsers.py](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhcnNlcnMucHk=) | `95.66% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.33% <0%> (+0.09%)` | :arrow_up: |
| [pandas/compat/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9fX2luaXRfXy5weQ==) | `62.22% <0%> (+0.44%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=footer). Last update [b0d9ee0...7c5f2c4](https://codecov.io/gh/pandas-dev/pandas/pull/16511?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

@jtratner : Thanks for this!  Seems like we need some more fuzzy-testing for `read_csv`...

One minor comment about the actual error message, and two bigger ones regarding the actual test.
okay, covered everybody's comments and moved tests again
@gfyoung @jreback - if either of you have a moment to look - all tests are green and I've made your changes.
@jtratner : LGTM!
thanks!