Skip to content
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

BUG+DOC: Recent Styler Enhancements #39317

Merged
merged 3 commits into from
Jan 24, 2021
Merged

Conversation

attack68
Copy link
Contributor

DOC: this edits the style.ipynb file to include examples of the 3 recent enhancements to Styler:

  • Tooltips
  • External CSS classes to datacells
  • Row and Column styling via table styles

It also addresses 3 minor bugs that I detected when wirting the documentation:

BUG1 (lines 696-703): set_td_classes only attached classes to 'diagonal elements' of the DataFrame due a misaligned comprehension loop:

{
r: {
   c: [str(classes.iloc[r, c])] 
   for c, cn in enumerate(classes.columns) if not mask.iloc[r, c]
   }
for r, rn in enumerate(classes.index)
}

replaces:

{
r: {
    c: [str(classes.iloc[r, c])]
    }
for r, rn in enumerate(classes.index)
for c, cn in enumerate(classes.columns)
if not mask.iloc[r, c]
}

BUG2 (lines 513 to 537): external css class names from the set_td_classes were appended to the HTML id tag, as well as the HTML class tag, due to a premature variable update relating to the row_dict. The solution was to re-order so that 'id' tags were generated first and then 'class' was updated with information from the new methods.

BUG3 (lines 1920-1925): Tooltips were generated for the wrong indexes/columns, since the null rows/columns were dropped and then the interger locations of rows/columns was mapped. The solution was to avoid dropping null rows/columns.

bug: set_td_classes loop ignored entries
bug: tooltips indexing was dropped
doc: added documentation for methods
@jreback jreback added Docs Styler conditional formatting using DataFrame.style labels Jan 21, 2021
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, some comments

cc @TomAugspurger

doc/source/user_guide/style.ipynb Outdated Show resolved Hide resolved
doc/source/user_guide/style.ipynb Outdated Show resolved Hide resolved
doc/source/user_guide/style.ipynb Outdated Show resolved Hide resolved
"- ``Styler.apply``: column-/row-/table-wise\n",
"\n",
"Both of those methods take a function (and some other keyword arguments) and applies your function to the DataFrame in a certain way.\n",
"`Styler.applymap` works through the DataFrame elementwise.\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how easy this is to link to the actual docs for these but would be great if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tried. i think it is possible but the relative path structure is quite complicated and i couldn't get it to work. never done it before so I have left out.

@jreback jreback added this to the 1.3 milestone Jan 21, 2021
@jreback
Copy link
Contributor

jreback commented Jan 21, 2021

@attack68 can you also add tests for the bugs you have fixed (e.g. simply a check on the generated html might be fine), just to lock down these cases.

@attack68 attack68 requested a review from jreback January 22, 2021 11:20
@attack68
Copy link
Contributor Author

@jreback think this is ready now..

@jreback jreback merged commit a1e8b59 into pandas-dev:master Jan 24, 2021
@jreback
Copy link
Contributor

jreback commented Jan 24, 2021

thanks @attack68

pls check the rendered docs when they build: https://pandas.pydata.org/docs/dev/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Styler conditional formatting using DataFrame.style
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants