Skip to content

BUG: styler hide_index hide_columns misaligns multiindex #43644

Closed
@attack68

Description

@attack68

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

midx = MultiIndex.from_product([["A", "B"], ["a", "b"], ["X", "Y"]], names=["zero", "one", "two"])
cidx = MultiIndex.from_product([["a", "b"], ["C", "D"], ["V", "W"]], names=["zero", "one", "two"])
df = DataFrame(np.arange(64).reshape(8,8), index=midx, columns=cidx)
styler = Styler(df)
styler.hide_index(level=1).hide_columns(level=0)
styler.hide_index([("A", "a", "X"), ("A", "b", "X")])
styler.hide_columns([("a", "C", "W"), ("a", "D", "V")])
styler

Issue Description

When using a MultiIndex and combining with hiding different levels and hiding specific rows/columns, some bugs appear.

Output is quite strange on second row for HTML output.

Screen Shot 2021-09-18 at 19 40 34

Also using LaTeX output:

>>> styler.to_latex()
\begin{tabular}{llrrrrrr}
 & one & C & D & \multicolumn{2}{r}{C} & \multicolumn{2}{r}{D} \\
 & two & V & W & V & W & V & W \\
zero & two &  &  &  &  &  &  \\
\multirow[c]{2}{*}{A} &  & Y & 8 & 11 & 12 & 13 & 14 & 15 \\
 &  & Y & 24 & 27 & 28 & 29 & 30 & 31 \\
\multirow[c]{4}{*}{B} & \multirow[c]{2}{*}{} & X & 32 & 35 & 36 & 37 & 38 & 39 \\
 &  & Y & 40 & 43 & 44 & 45 & 46 & 47 \\
 & \multirow[c]{2}{*}{} & X & 48 & 51 & 52 & 53 & 54 & 55 \\
 &  & Y & 56 & 59 & 60 & 61 & 62 & 63 \\
\end{tabular}

The above is a LaTeX error but if the number of columns is expanded to 9 then it renders like:
Screen Shot 2021-09-18 at 19 43 51

Expected Behavior

Clearly we want to align all the datapoints and have the hidden levels correctly hidden.

Installed Versions

master

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO HTMLread_html, to_html, Styler.apply, Styler.applymapIO LaTeXto_latexStylerconditional formatting using DataFrame.style

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions