Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Fix unbound local with bad engine #16511
Conversation
|
(or if you want to do this a totally different way / different error I can make changes or close) |
| @@ -83,6 +83,8 @@ Performance Improvements | ||
| Bug Fixes | ||
| ~~~~~~~~~ | ||
| +- Passing an invalid engine to `read_csv` now raises an informative ValueError rather than UnboundLocalError. (:issue:`16511`) |
| @@ -99,3 +102,14 @@ def read_table(self, *args, **kwds): | ||
| kwds = kwds.copy() | ||
| kwds['engine'] = self.engine | ||
| return read_table(*args, **kwds) | ||
| + | ||
| + | ||
| +class TestParameterValidation(object): |
gfyoung
May 26, 2017
•
Member
Let's move this test into common.py (in same directory). This base test class should not be touched for organizational purposes.
gfyoung
May 26, 2017
•
Member
Also, why are we writing a round trip test? This can be much simpler:
data = "a\n1"
msg = "Unknown engine"
with tm.assert_raises_regex(ValueError, msg):
read_csv(StringIO(data), engine='pyt') # don't use self.read_csv because that will override the engine parameterOh and yes, use tm.assert_raises_regex instead of the pytest.raises(...) (pandas regex error message matching is a little more compact).
jtratner
May 26, 2017
Contributor
so okay that this will get run once for every engine, even though it's the same test?
gfyoung
May 26, 2017
Member
Yikes! You're right. We changed our minds about that. Mind fixing the documentation on that in a separate commit / PR?
gfyoung
May 26, 2017
Member
so okay that this will get run once for every engine, even though it's the same test?
Actually, better idea: move it to test_common.py (the directory above)
| + def test_unknown_engine(self): | ||
| + with tempfile.NamedTemporaryFile() as fp: | ||
| + df = tm.makeDataFrame() | ||
| + df.to_csv(fp.name) |
gfyoung
May 26, 2017
Member
No. There shouldn't be any tests in this file. I made a comment here about it.
jreback
added Error Reporting IO CSV
labels
May 26, 2017
|
made all the requested changes - thanks for the review @jreback ! |
codecov
bot
commented
May 26, 2017
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
codecov
bot
commented
May 26, 2017
•
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
| @@ -969,6 +969,9 @@ def _make_engine(self, engine='c'): | ||
| klass = PythonParser | ||
| elif engine == 'python-fwf': | ||
| klass = FixedWidthFieldParser | ||
| + else: | ||
| + raise ValueError('Unknown engine: %r (valid are "c", "python",' |
|
@jtratner : Thanks for this! Seems like we need some more fuzzy-testing for One minor comment about the actual error message, and two bigger ones regarding the actual test. |
| @@ -39,6 +39,9 @@ Bug Fixes | ||
| - 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`) |
| @@ -969,6 +969,9 @@ def _make_engine(self, engine='c'): | ||
| klass = PythonParser | ||
| elif engine == 'python-fwf': | ||
| klass = FixedWidthFieldParser | ||
| + else: | ||
| + raise ValueError('Unknown engine: %r (valid are "c", "python",' | ||
| + ' or "python-fwf")' % engine) |
|
okay, covered everybody's comments and moved tests again |
gfyoung
referenced
this pull request
May 27, 2017
Merged
DOC: Remove preference for pytest paradigm in assert_raises_regex #16518
|
@jtratner : LGTM! |
jreback
added this to the
0.20.2
milestone
May 31, 2017
jreback
merged commit 9b0ea41
into pandas-dev:master
May 31, 2017
5 checks passed
|
thanks! |
jreback
added the
Needs Backport
label
May 31, 2017
jtratner
deleted the
jtratner:fix-unbound-local-with-bad-engine branch
May 31, 2017
TomAugspurger
added a commit
to TomAugspurger/pandas
that referenced
this pull request
Jun 1, 2017
|
|
jtratner + TomAugspurger |
fe88fce
|
TomAugspurger
added a commit
that referenced
this pull request
Jun 4, 2017
|
|
jtratner + TomAugspurger |
d0fe59c
|
TomAugspurger
removed the
Needs Backport
label
Jun 4, 2017
chris-b1
referenced
this pull request
Jun 8, 2017
Closed
read_table should check for engine name validity #16641
Kiv
added a commit
to Kiv/pandas
that referenced
this pull request
Jun 11, 2017
|
|
jtratner + Kiv |
ab9bc9a
|
stangirala
added a commit
to stangirala/pandas
that referenced
this pull request
Jun 11, 2017
|
|
jtratner + stangirala |
02d7c80
|
guillemborrell
added a commit
to guillemborrell/pandas
that referenced
this pull request
Jul 7, 2017
|
|
jtratner + guillemborrell |
2d80876
|
jtratner commentedMay 26, 2017
•
edited
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:
Now it gives a much nicer ValueError:
git diff upstream/master --name-only -- '*.py' | flake8 --diffI 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!