Skip to content

Commit d170cc0

Browse files
jbrockmendeljreback
authored andcommitted
TST/BUG: fix incorrectly-passing Exception (pandas-dev#30553)
1 parent cdf6774 commit d170cc0

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

pandas/io/html.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -591,9 +591,14 @@ def _setup_build_doc(self):
591591
def _build_doc(self):
592592
from bs4 import BeautifulSoup
593593

594-
return BeautifulSoup(
595-
self._setup_build_doc(), features="html5lib", from_encoding=self.encoding
596-
)
594+
bdoc = self._setup_build_doc()
595+
if isinstance(bdoc, bytes) and self.encoding is not None:
596+
udoc = bdoc.decode(self.encoding)
597+
from_encoding = None
598+
else:
599+
udoc = bdoc
600+
from_encoding = self.encoding
601+
return BeautifulSoup(udoc, features="html5lib", from_encoding=from_encoding)
597602

598603

599604
def _build_xpath_expr(attrs) -> str:

pandas/tests/io/test_html.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1158,9 +1158,9 @@ def test_displayed_only(self, displayed_only, exp0, exp1):
11581158
assert len(dfs) == 1 # Should not parse hidden table
11591159

11601160
def test_encode(self, html_encoding_file):
1161-
_, encoding = os.path.splitext(os.path.basename(html_encoding_file))[0].split(
1162-
"_"
1163-
)
1161+
base_path = os.path.basename(html_encoding_file)
1162+
root = os.path.splitext(base_path)[0]
1163+
_, encoding = root.split("_")
11641164

11651165
try:
11661166
with open(html_encoding_file, "rb") as fobj:
@@ -1183,7 +1183,7 @@ def test_encode(self, html_encoding_file):
11831183
if is_platform_windows():
11841184
if "16" in encoding or "32" in encoding:
11851185
pytest.skip()
1186-
raise
1186+
raise
11871187

11881188
def test_parse_failure_unseekable(self):
11891189
# Issue #17975

0 commit comments

Comments
 (0)