great-tables icon indicating copy to clipboard operation
great-tables copied to clipboard

feat: Add `fmt_image_circle()` and `vals.fmt_image_circle()` functions

Open jrycw opened this issue 7 months ago • 1 comments

Hello team,

This PR addresses #354.

Rather than modifying the existing fmt_image() to accommodate border-related parameters, I have renamed the current fmt_image() to _fmt_image(), and introduced new fmt_image() and fmt_image_circle() functions as thin wrappers around it. Keeping _fmt_image() and FmtImage under our control gives us greater flexibility to add more parameters in the future if needed.

Here’s a short demo to illustrate the usage:

import polars as pl
from great_tables import GT, vals, html

posit_avatar = "https://avatars.githubusercontent.com/u/107264312?s=200&v=4"
rich_avatar = "https://avatars.githubusercontent.com/u/5612024?v=4"
michael_avatar = "https://avatars.githubusercontent.com/u/2574498?v=4"

title_img = vals.fmt_image_circle(posit_avatar, height=100, border_color="#D3D3D3")[0]
df = pl.DataFrame({"@rich-iannone": [rich_avatar], "@machow": [michael_avatar]})

(
    GT(df)
    .fmt_image_circle(height=150, border_width=5)
    .tab_header(html(title_img))
    .cols_align("center")
    .opt_stylize(color="green", style=6)
)

image

One thing that seems odd to me is that NotImplementedError doesn’t appear to be raised as expected during execution, yet our tests still pass.

For instance, when running the following code, I would expect it to break, but instead, the print statement after vals.fmt_image() is executed successfully, which feels strange.

import polars as pl
from great_tables import GT

df = pl.DataFrame({"col1": ["https://avatars.githubusercontent.com/u/107264312?s=200&v=4"]})

print(GT(df).fmt_image(width=100)) # Is `NotImplementedError` actually being raised?
print("still running???")

jrycw avatar Apr 26 '25 10:04 jrycw