Skip to content

Commit cbb6fe8

Browse files
committed
import io/html.py as needed
1 parent be1bbfe commit cbb6fe8

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

pandas/io/html.py

+31-18
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,40 @@
2020
from pandas.core import common as com
2121
from pandas import Series
2222

23+
_IMPORTS = False
24+
_HAS_BS4 = False
25+
_HAS_LXML = False
26+
_HAS_HTML5LIB = False
2327

24-
try:
25-
import bs4
26-
except ImportError:
27-
_HAS_BS4 = False
28-
else:
29-
_HAS_BS4 = True
28+
def _importers():
29+
# import things we need
30+
# but make this done on a first use basis
3031

32+
global _IMPORTS
33+
if _IMPORTS:
34+
return
3135

32-
try:
33-
import lxml
34-
except ImportError:
35-
_HAS_LXML = False
36-
else:
37-
_HAS_LXML = True
36+
_IMPORTS = True
3837

38+
global _HAS_BS4, _HAS_LXML, _HAS_HTML5LIB
3939

40-
try:
41-
import html5lib
42-
except ImportError:
43-
_HAS_HTML5LIB = False
44-
else:
45-
_HAS_HTML5LIB = True
40+
try:
41+
import bs4
42+
_HAS_BS4 = True
43+
except ImportError:
44+
pass
45+
46+
try:
47+
import lxml
48+
_HAS_LXML = True
49+
except ImportError:
50+
pass
51+
52+
try:
53+
import html5lib
54+
_HAS_HTML5LIB = True
55+
except ImportError:
56+
pass
4657

4758

4859
#############
@@ -651,6 +662,7 @@ def _parser_dispatch(flavor):
651662
raise ImportError("html5lib not found, please install it")
652663
if not _HAS_BS4:
653664
raise ImportError("BeautifulSoup4 (bs4) not found, please install it")
665+
import bs4
654666
if bs4.__version__ == LooseVersion('4.2.0'):
655667
raise ValueError("You're using a version"
656668
" of BeautifulSoup4 (4.2.0) that has been"
@@ -839,6 +851,7 @@ def read_html(io, match='.+', flavor=None, header=None, index_col=None,
839851
--------
840852
pandas.read_csv
841853
"""
854+
_importers()
842855
if infer_types is not None:
843856
warnings.warn("infer_types has no effect since 0.15", FutureWarning)
844857

0 commit comments

Comments
 (0)