diff --git a/pandas/io/html.py b/pandas/io/html.py index af723cdebd850..d6d1c5651dd37 100644 --- a/pandas/io/html.py +++ b/pandas/io/html.py @@ -53,33 +53,6 @@ if TYPE_CHECKING: from pandas import DataFrame -_IMPORTS = False -_HAS_BS4 = False -_HAS_LXML = False -_HAS_HTML5LIB = False - - -def _importers() -> None: - # import things we need - # but make this done on a first use basis - - global _IMPORTS - if _IMPORTS: - return - - global _HAS_BS4, _HAS_LXML, _HAS_HTML5LIB - bs4 = import_optional_dependency("bs4", errors="ignore") - _HAS_BS4 = bs4 is not None - - lxml = import_optional_dependency("lxml.etree", errors="ignore") - _HAS_LXML = lxml is not None - - html5lib = import_optional_dependency("html5lib", errors="ignore") - _HAS_HTML5LIB = html5lib is not None - - _IMPORTS = True - - ############# # READ HTML # ############# @@ -922,16 +895,10 @@ def _parser_dispatch(flavor: str | None) -> type[_HtmlFrameParser]: ) if flavor in ("bs4", "html5lib"): - if not _HAS_HTML5LIB: - raise ImportError("html5lib not found, please install it") - if not _HAS_BS4: - raise ImportError("BeautifulSoup4 (bs4) not found, please install it") - # Although we call this above, we want to raise here right before use. - bs4 = import_optional_dependency("bs4") # noqa:F841 - + import_optional_dependency("html5lib") + import_optional_dependency("bs4") else: - if not _HAS_LXML: - raise ImportError("lxml not found, please install it") + import_optional_dependency("lxml.etree") return _valid_parsers[flavor] @@ -1194,8 +1161,6 @@ def read_html( See the :ref:`read_html documentation in the IO section of the docs ` for some examples of reading in HTML tables. """ - _importers() - # Type check here. We don't want to parse only to fail because of an # invalid value of an integer skiprows. if isinstance(skiprows, numbers.Integral) and skiprows < 0: diff --git a/pandas/tests/io/test_html.py b/pandas/tests/io/test_html.py index 47cff87834956..514d96a4d9ec6 100644 --- a/pandas/tests/io/test_html.py +++ b/pandas/tests/io/test_html.py @@ -1,5 +1,4 @@ from functools import partial -from importlib import reload from io import ( BytesIO, StringIO, @@ -26,6 +25,7 @@ Timestamp, date_range, read_csv, + read_html, to_datetime, ) import pandas._testing as tm @@ -36,7 +36,6 @@ from pandas.io.common import file_path_to_url import pandas.io.html -from pandas.io.html import read_html @pytest.fixture( @@ -1350,9 +1349,6 @@ def run(self): else: self.err = None - # force import check by reinitalising global vars in html.py - reload(pandas.io.html) - filename = datapath("io", "data", "html", "valid_markup.html") helper_thread1 = ErrorThread(target=self.read_html, args=(filename,)) helper_thread2 = ErrorThread(target=self.read_html, args=(filename,))