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

BUG: Fix error message for invalid HTML flavor #23550

Merged
merged 1 commit into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,7 @@ Notice how we now instead output ``np.nan`` itself instead of a stringified form
- Bug in :func:`DataFrame.to_csv` where a single level MultiIndex incorrectly wrote a tuple. Now just the value of the index is written (:issue:`19589`).
- Bug in :meth:`HDFStore.append` when appending a :class:`DataFrame` with an empty string column and ``min_itemsize`` < 8 (:issue:`12242`)
- Bug in :meth:`read_csv()` in which :class:`MultiIndex` index names were being improperly handled in the cases when they were not provided (:issue:`23484`)
- Bug in :meth:`read_html()` in which the error message was not displaying the valid flavors when an invalid one was provided (:issue:`23549`)

Plotting
^^^^^^^^
Expand Down
3 changes: 2 additions & 1 deletion pandas/io/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,8 @@ def _parser_dispatch(flavor):


def _print_as_set(s):
return '{{arg}}'.format(arg=', '.join(pprint_thing(el) for el in s))
return ('{' + '{arg}'.format(arg=', '.join(
pprint_thing(el) for el in s)) + '}')


def _validate_flavor(flavor):
Expand Down
9 changes: 6 additions & 3 deletions pandas/tests/io/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ def test_bs4_version_fails(monkeypatch, datapath):


def test_invalid_flavor():
url = 'google.com'
with pytest.raises(ValueError):
read_html(url, 'google', flavor='not a* valid**++ flaver')
url = "google.com"
flavor = "invalid flavor"
msg = r"\{" + flavor + r"\} is not a valid set of flavors"

with tm.assert_raises_regex(ValueError, msg):
read_html(url, "google", flavor=flavor)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had a test for invalid flavors, but we were not checking the error message 😮

Should definitely discourage use of pytest.raises (with no match argument) unless there is a good reason for our not wanting to check the error message.



@td.skip_if_no('bs4')
Expand Down