You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The flavor parameter has the incorret type hint in the read_html(...) function.
Currently, the type hint is an optional str. However, according to the documentation in io.html it is possible to pass a list-like:
The lxml backend will raise an error on a failed parse if that is the only parser you provide.
If you only have a single parser you can provide just a string, but it is considered good practice
to pass a list with one string if, for example, the function expects a sequence of strings. You may use:
>>> dfs = pd.read_html(url, "Metcalf Bank", index_col=0, flavor=["lxml"])
Or you could pass flavor='lxml' without a list:
>>> dfs = pd.read_html(url, "Metcalf Bank", index_col=0, flavor="lxml")
However, if you have bs4 and html5lib installed and pass None or ['lxml', 'bs4'] then the parse will
most likely succeed. Note that as soon as a parse succeeds, the function will return.
>>> dfs = pd.read_html(url, "Metcalf Bank", index_col=0, flavor=["lxml", "bs4"])
Internally read_html(...) converts the passed value to a tuple in both cases.
With this incorrect type hint, type checkers throw an error when passed a list-like:
Solution
We can set the type hint to a str or a Sequence[str], both of which are optional:
flavor: str|Sequence[str] |None=None
I can resolve this and create a PR by updating the type hints, docstrings and documentation. Just let me know if you agree with my solution.
The text was updated successfully, but these errors were encountered:
* Fix flavor param with incorrect type hint in read_html
refs:
- pandas-dev/pandas#55059
- pandas-dev/pandas#55076
* Add HTMLFlavors type to read_html
ref: pandas-dev/pandas#55529
* Add tests and new dev dependencies
Added:
- tests to check HTMLFlavors type in read_html flavor arg;
- set beautifulsoup4 and html5lib as dev dependencies. They are used
by the respective flavors in read_html.
Problem
The
flavor
parameter has the incorret type hint in theread_html(...)
function.Currently, the type hint is an optional
str
. However, according to the documentation in io.html it is possible to pass a list-like:Internally
read_html(...)
converts the passed value to atuple
in both cases.With this incorrect type hint, type checkers throw an error when passed a list-like:
Solution
We can set the type hint to a
str
or aSequence[str]
, both of which are optional:I can resolve this and create a PR by updating the type hints, docstrings and documentation. Just let me know if you agree with my solution.
The text was updated successfully, but these errors were encountered: