Skip to content

ENH: Styler tooltips feature #35643

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

Merged
merged 50 commits into from
Jan 17, 2021
Merged

Conversation

attack68
Copy link
Contributor

@attack68 attack68 commented Aug 9, 2020

This is a draft PR to address 21266: Tooltips for DataFrames in Styler.

This PR has the following objectives:

  1. Add functionality whilst being completely (almost) decoupled from the rest of the HTML rendering process
  2. Be fully backwards compatible and have no impact at all on previous Styler's that have never used tooltips.
  3. Use pseudo CSS class rendering via table_styles to control the visualisation of the tooltips.

To address 1) the architecture was simple:

  • If tooltips are detected then an additional HTML element is added to every data cell: <span class="pd-t"></span>. If tooltips are not detected (by default) nothing is done.
  • Add generic table level CSS for the tooltip class, hiding tooltips by default but positioning, sizing, and coloring them.
  • Loop through a tooltips DataFrame and based on the row and col index add additional content to the element using the ::after pseudo-element targeting the exact cell id. This is table level also. Rendering is performed as the last step.

To address 2) default values ensure the functions make no changes unless set_tooltips has been called.

Extensions

The very simple architecture requires a DataFrame of tooltips to be supplied. This requires the user to have constructed it privately (possibly using the regular DataFrame.apply and DataFrame.applymap) methods. These could be incorporated.

It would also be better to only add extra HTML elements to data cells that have tooltips. This requires conditional looping of the render dict, which I haven't included here to save on initial complexity. For small dataframes it is also irrelevant.

However, given my time constraints I would rather leave this to a more available and more competent developer!!

Comments welcome..

@pep8speaks
Copy link

pep8speaks commented Aug 9, 2020

Hello @attack68! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-01-16 10:41:11 UTC

@attack68 attack68 changed the title Styler tooltips feature ENH: Styler tooltips feature Aug 9, 2020
@attack68 attack68 marked this pull request as draft August 9, 2020 12:53
@attack68 attack68 marked this pull request as ready for review August 9, 2020 13:35
@jreback jreback added Styler conditional formatting using DataFrame.style Enhancement labels Aug 13, 2020
@attack68 attack68 force-pushed the styler_tooltips_feature branch from cdaf9d9 to 1598830 Compare August 18, 2020 09:52
@attack68
Copy link
Contributor Author

@reviewers: this is ready to be reviewed. All green, except for known unrelated issues

@attack68 attack68 force-pushed the styler_tooltips_feature branch from 6a69f83 to c18103b Compare August 26, 2020 06:04
@attack68 attack68 force-pushed the styler_tooltips_feature branch from c18103b to f798852 Compare August 28, 2020 16:00
@attack68
Copy link
Contributor Author

@TomAugspurger @WillAyd you both commented on the underlying issue. Would you care to review this pull request for suitability?

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Aug 31, 2020 via email

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 reasonable, some comments

@@ -1241,4 +1241,4 @@
},
"nbformat": 4,
"nbformat_minor": 1
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can you revert this

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've no real experience with selected git revert, doesn't it just get squashed?

Copy link
Member

Choose a reason for hiding this comment

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

git checkout upstream/master doc/source/user_guide/style.ipynb and commit the result

@github-actions github-actions bot added the Stale label Oct 30, 2020
@attack68
Copy link
Contributor Author

attack68 commented Nov 6, 2020

@jreback @WillAyd this is still live, but it needs agreement on whether you want list comprehensions (previous change request) or not (new request), style wise.

to be honest I think the latest version (jreback's request) is cleanest.

@hamishdarbyshire
Copy link

would be good to to have the 1.2 milestone on this and then I can work on improving the documentation for all the Styler enhancements I have contributed in subsequent minor versions..

@jreback

@attack68
Copy link
Contributor Author

apologies for posting with wrong account above: work not personal.

@attack68
Copy link
Contributor Author

@WillAyd @jreback can this get a 1.2 milestone tag - all my other Styler PRs made it in and it would be great if this last one could be added.

I can then update the documentation notebook with examples of all new features.

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.

i know you really want this for 1.2, but it needs some work, if you can turn it around shortly then we can do

@@ -540,6 +627,7 @@ def render(self, **kwargs) -> str:
self._compute()
# TODO: namespace all the pandas keys
d = self._translate()
d = self.tooltips._translate_tooltips(self.data, self.uuid, d)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is very confusing here, why is this not part of _translate itself?

for style in sublist
]

if self.table_styles:
Copy link
Contributor

Choose a reason for hiding this comment

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

i am puzzled by this here why this is involved at all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the above table_styles will be an empty list if there are no tooltips to add, i.e if the mask was empty. In that case this if check provides some efficiency by avoiding adding a <span> html selector to every table cell.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok can you add that as a comment

Copy link
Contributor

Choose a reason for hiding this comment

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

can you update this

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 added a comment line 1938?

@attack68 attack68 requested review from jreback and WillAyd January 8, 2021 07:22
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 small comments. ping on green.

assume that you will do a followon to add docs to the style notebook? (can also be in this PR)

for style in sublist
]

if self.table_styles:
Copy link
Contributor

Choose a reason for hiding this comment

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

ok can you add that as a comment

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 a question and comment.

for style in sublist
]

if self.table_styles:
Copy link
Contributor

Choose a reason for hiding this comment

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

can you update this

@attack68 attack68 requested a review from jreback January 14, 2021 18:45
@jreback
Copy link
Contributor

jreback commented Jan 14, 2021

ok @attack68 can you resolve this precommit issue:
pandas/io/formats/style.py:809: error: Attribute 'tooltips' already defined on line 185 [no-redef]

merge master and ping on green-ish

@attack68 attack68 force-pushed the styler_tooltips_feature branch from a29719d to 54c52da Compare January 16, 2021 10:41
@attack68
Copy link
Contributor Author

@jreback fixed, green-ish... ping.

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.

thanks @attack68

would not object to a PR to split up pandas/io/formats/style.py to submodules in the future as this file is getting kind of long / including multiple functionaility.

@jreback jreback added this to the 1.3 milestone Jan 17, 2021
@jreback jreback merged commit 085ba15 into pandas-dev:master Jan 17, 2021
@simonjayhawkins
Copy link
Member

@jreback this broke pre-commit on master. will fix up shortly so feel free to carry on merging PRs to master

@jreback
Copy link
Contributor

jreback commented Jan 17, 2021

thanks @simonjayhawkins

luckyvs1 pushed a commit to luckyvs1/pandas that referenced this pull request Jan 20, 2021
@attack68 attack68 deleted the styler_tooltips_feature branch January 21, 2021 06:46
nofarm3 pushed a commit to nofarm3/pandas that referenced this pull request Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Stale Styler conditional formatting using DataFrame.style
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement Request] Styler support for tooltips.
7 participants