ENH: Styler tooltips feature
State: closed

- [x] closes #21266 
- [x] tests added / passed
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

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 <span> 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 <span> 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..


Labels:
name: Enhancement
name: Styler
description: conditional formatting using DataFrame.style
name: Stale

Comments:
Hello @attack68! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:





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

##### Comment last updated at 2021-01-16 10:41:11 UTC
@reviewers: this is ready to be reviewed. All green, except for known unrelated issues
@TomAugspurger @WillAyd  you both commented on the underlying issue. Would you care to review this pull request for suitability?  
It'll be a while before I can look. No need to hold it up for me.

On Fri, Aug 28, 2020 at 2:10 PM attack68 <notifications@github.com> wrote:

> @TomAugspurger <https://github.com/TomAugspurger> @WillAyd
> <https://github.com/WillAyd> you both commented on the underlying issue.
> Would you care to review this pull request for suitability?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/35643#issuecomment-683093505>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAKAOIXGGVOYJUO2GU73BJ3SC76JNANCNFSM4PZFPFBQ>
> .
>

I changed to use reindex for the dataframe shapes similar to #36159 and the comment from @TomAugspurger there. Added test cases.
This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.
@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.


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 
apologies for posting with wrong account above: work not personal.
@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.
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
@jreback fixed, green-ish... ping.
@jreback this broke pre-commit on master. will fix up shortly so feel free to carry on merging PRs to master
thanks @simonjayhawkins