Skip to content

BUG: styler hide_index hide_columns misaligns multiindex #43644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
attack68 opened this issue Sep 18, 2021 · 0 comments · Fixed by #43649
Closed
3 tasks done

BUG: styler hide_index hide_columns misaligns multiindex #43644

attack68 opened this issue Sep 18, 2021 · 0 comments · Fixed by #43649
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap IO LaTeX to_latex Styler conditional formatting using DataFrame.style
Milestone

Comments

@attack68
Copy link
Contributor

  • 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

@attack68 attack68 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 18, 2021
@attack68 attack68 added Styler conditional formatting using DataFrame.style IO HTML read_html, to_html, Styler.apply, Styler.applymap IO LaTeX to_latex and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 19, 2021
@jreback jreback added this to the 1.4 milestone Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap IO LaTeX to_latex Styler conditional formatting using DataFrame.style
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants