Skip to content

Commit d734b3b

Browse files
gfyoungtm9k1
authored andcommitted
BUG: Fix error message for invalid HTML flavor (pandas-dev#23550)
The flavors were not rendering properly in the string formatting. Closes pandas-devgh-23549. Follow-up to pandas-devgh-17660.
1 parent 8ce02ff commit d734b3b

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

doc/source/whatsnew/v0.24.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,7 @@ Notice how we now instead output ``np.nan`` itself instead of a stringified form
12931293
- 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`).
12941294
- Bug in :meth:`HDFStore.append` when appending a :class:`DataFrame` with an empty string column and ``min_itemsize`` < 8 (:issue:`12242`)
12951295
- 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`)
1296+
- Bug in :meth:`read_html()` in which the error message was not displaying the valid flavors when an invalid one was provided (:issue:`23549`)
12961297

12971298
Plotting
12981299
^^^^^^^^

pandas/io/html.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,8 @@ def _parser_dispatch(flavor):
854854

855855

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

859860

860861
def _validate_flavor(flavor):

pandas/tests/io/test_html.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@ def test_bs4_version_fails(monkeypatch, datapath):
6161

6262

6363
def test_invalid_flavor():
64-
url = 'google.com'
65-
with pytest.raises(ValueError):
66-
read_html(url, 'google', flavor='not a* valid**++ flaver')
64+
url = "google.com"
65+
flavor = "invalid flavor"
66+
msg = r"\{" + flavor + r"\} is not a valid set of flavors"
67+
68+
with tm.assert_raises_regex(ValueError, msg):
69+
read_html(url, "google", flavor=flavor)
6770

6871

6972
@td.skip_if_no('bs4')

0 commit comments

Comments
 (0)