make_tooltip

make_tooltip(
    label,
    tooltip,
    text_decoration_style='dotted',
    color='blue',
    *,
    name='tooltip',
)

Returns a Polars expression that generates an HTML tooltip for each row.

This function is heavily inspired by the gt-extras package.

Parameters

label : str

Column name containing the main text to display.

tooltip : str

Column name containing containing the text shown when hovering over the label.

text_decoration_style : Literal['solid', 'dotted', 'none'] = 'dotted'

A string indicating the style of underline decoration. Options are "solid", "dotted", or "none".

color : str | Literal['none'] = 'blue'

A string indicating the text color. If “none”, no color styling is applied.

name : str = 'tooltip'

The name of the resulting column.

Returns

: pl.Expr

A Polars expression that creates an HTML string with tooltip functionality.

Examples

DataFrame Context

import polars as pl
import turtle_island as ti

pl.Config.set_fmt_str_lengths(200)
df = pl.DataFrame(
    {
        "name": ["Turtle Island"],
        "description": ["A Utility Kit for Polars Expressions"],
    }
)
new_df = df.with_columns(ti.make_tooltip("name", "description"))
new_df
shape: (1, 3)
namedescriptiontooltip
strstrstr
"Turtle Island""A Utility Kit for Polars Expressions""<abbr style="cursor: help; text-decoration: underline; text-decoration-style: dotted; color: blue; " title="A Utility Kit for Polars Expressions">Turtle Island</abbr>"
new_df.style
name description tooltip
Turtle Island A Utility Kit for Polars Expressions Turtle Island