-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Fix unbound local with bad engine #16511
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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",' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about |
||
' or "python-fwf")' % engine) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you use |
||
self._engine = klass(self.f, **self.options) | ||
|
||
def _failover_to_python(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
import os | ||
|
||
import pytest | ||
|
||
import pandas.util.testing as tm | ||
|
||
from pandas import read_csv, read_table | ||
|
@@ -99,3 +101,13 @@ def read_table(self, *args, **kwds): | |
kwds = kwds.copy() | ||
kwds['engine'] = self.engine | ||
return read_table(*args, **kwds) | ||
|
||
|
||
class TestParameterValidation(object): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move this test into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 parameter Oh and yes, use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docstring for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so okay that this will get run once for every engine, even though it's the same test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yikes! You're right. We changed our minds about that. Mind fixing the documentation on that in a separate commit / PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Actually, better idea: move it to |
||
def test_unknown_engine(self): | ||
with tm.ensure_clean() as path: | ||
df = tm.makeDataFrame() | ||
df.to_csv(path) | ||
with pytest.raises(ValueError) as exc_info: | ||
read_csv(path, engine='pyt') | ||
exc_info.match('Unknown engine') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double backtics on
ValueError
andUnboundLocalError