Skip to content

Commit ba7caab

Browse files
committed
Simplify MultiIndex -> Index conversion
1 parent 7389b84 commit ba7caab

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

pandas/io/html.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
cast,
1818
)
1919

20-
import numpy as np
21-
2220
from pandas._typing import (
2321
FilePath,
2422
ReadBuffer,
@@ -32,6 +30,7 @@
3230

3331
from pandas.core.dtypes.common import is_list_like
3432

33+
from pandas import isna
3534
from pandas.core.construction import create_series_with_explicit_dtype
3635
from pandas.core.frame import DataFrame
3736
from pandas.core.indexes.base import Index
@@ -1007,15 +1006,13 @@ def _parse(flavor, io, match, attrs, encoding, displayed_only, extract_links, **
10071006
try:
10081007
df = _data_to_frame(data=table, **kwargs)
10091008
# Cast MultiIndex header to an Index of tuples when extracting header
1010-
# links and replace np.nan with None.
1009+
# links and replace nan with None.
10111010
# This maintains consistency of selection (e.g. df.columns.str[1])
10121011
if extract_links in ("all", "header"):
1013-
idx = df.columns.values
1014-
idx[:] = np.vectorize(
1015-
lambda cols: tuple(None if col is np.nan else col for col in cols),
1016-
otypes=["object"],
1017-
)(idx)
1018-
df.columns = Index(df.columns)
1012+
df.columns = Index(
1013+
((col[0], None if isna(col[1]) else col[1]) for col in df.columns),
1014+
tupleize_cols=False,
1015+
)
10191016

10201017
ret.append(df)
10211018
except EmptyDataError: # empty table

0 commit comments

Comments
 (0)