Skip to content

feat: Add fmt_image_circle() and vals.fmt_image_circle() functions #676

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jrycw
Copy link
Collaborator

@jrycw jrycw commented Apr 26, 2025

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???")

Copy link

codecov bot commented Apr 26, 2025

Codecov Report

Attention: Patch coverage is 97.36842% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.21%. Comparing base (ae0204c) to head (ba5ba7f).

Files with missing lines Patch % Lines
great_tables/_formats.py 96.87% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #676      +/-   ##
==========================================
+ Coverage   91.17%   91.21%   +0.03%     
==========================================
  Files          47       47              
  Lines        5462     5495      +33     
==========================================
+ Hits         4980     5012      +32     
- Misses        482      483       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant