|
53 | 53 | if TYPE_CHECKING:
|
54 | 54 | from pandas import DataFrame
|
55 | 55 |
|
56 |
| -_IMPORTS = False |
57 |
| -_HAS_BS4 = False |
58 |
| -_HAS_LXML = False |
59 |
| -_HAS_HTML5LIB = False |
60 |
| - |
61 |
| - |
62 |
| -def _importers() -> None: |
63 |
| - # import things we need |
64 |
| - # but make this done on a first use basis |
65 |
| - |
66 |
| - global _IMPORTS |
67 |
| - if _IMPORTS: |
68 |
| - return |
69 |
| - |
70 |
| - global _HAS_BS4, _HAS_LXML, _HAS_HTML5LIB |
71 |
| - bs4 = import_optional_dependency("bs4", errors="ignore") |
72 |
| - _HAS_BS4 = bs4 is not None |
73 |
| - |
74 |
| - lxml = import_optional_dependency("lxml.etree", errors="ignore") |
75 |
| - _HAS_LXML = lxml is not None |
76 |
| - |
77 |
| - html5lib = import_optional_dependency("html5lib", errors="ignore") |
78 |
| - _HAS_HTML5LIB = html5lib is not None |
79 |
| - |
80 |
| - _IMPORTS = True |
81 |
| - |
82 |
| - |
83 | 56 | #############
|
84 | 57 | # READ HTML #
|
85 | 58 | #############
|
@@ -922,16 +895,10 @@ def _parser_dispatch(flavor: str | None) -> type[_HtmlFrameParser]:
|
922 | 895 | )
|
923 | 896 |
|
924 | 897 | if flavor in ("bs4", "html5lib"):
|
925 |
| - if not _HAS_HTML5LIB: |
926 |
| - raise ImportError("html5lib not found, please install it") |
927 |
| - if not _HAS_BS4: |
928 |
| - raise ImportError("BeautifulSoup4 (bs4) not found, please install it") |
929 |
| - # Although we call this above, we want to raise here right before use. |
930 |
| - bs4 = import_optional_dependency("bs4") # noqa:F841 |
931 |
| - |
| 898 | + import_optional_dependency("html5lib") |
| 899 | + import_optional_dependency("bs4") |
932 | 900 | else:
|
933 |
| - if not _HAS_LXML: |
934 |
| - raise ImportError("lxml not found, please install it") |
| 901 | + import_optional_dependency("lxml.etree") |
935 | 902 | return _valid_parsers[flavor]
|
936 | 903 |
|
937 | 904 |
|
@@ -1194,8 +1161,6 @@ def read_html(
|
1194 | 1161 | See the :ref:`read_html documentation in the IO section of the docs
|
1195 | 1162 | <io.read_html>` for some examples of reading in HTML tables.
|
1196 | 1163 | """
|
1197 |
| - _importers() |
1198 |
| - |
1199 | 1164 | # Type check here. We don't want to parse only to fail because of an
|
1200 | 1165 | # invalid value of an integer skiprows.
|
1201 | 1166 | if isinstance(skiprows, numbers.Integral) and skiprows < 0:
|
|
0 commit comments