Skip to content
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

feat: add fmt_icon() method #515

Merged
merged 21 commits into from
Dec 10, 2024
Merged

feat: add fmt_icon() method #515

merged 21 commits into from
Dec 10, 2024

Conversation

rich-iannone
Copy link
Member

This PR adds the fmt_icon() method. It depends on Font Awesome icons available in the faicons library, so that is a new dependency. Whenever that package is updated, new icons from the FA free set will be available. Here's an example of the fmt_icon() method in use:

import pandas as pd
from great_tables import GT
animals_foods_df = pd.DataFrame(
    {
        "animals": ["hippo", "fish,spider", "mosquito,locust,frog", "dog,cat", "kiwi-bird"],
        "foods": ["bowl-rice", "egg,pizza-slice", "burger,lemon,cheese", "carrot,hotdog", "bacon"],
    }
)
(
    GT(animals_foods_df)
    .fmt_icon(
        columns=["animals", "foods"],
        height="4em"
    )
    .cols_align(
        align="center",
        columns=["animals", "foods"]
    )
)
image

Copy link

codecov bot commented Nov 20, 2024

Codecov Report

Attention: Patch coverage is 90.56604% with 5 lines in your changes missing coverage. Please review.

Project coverage is 89.79%. Comparing base (549b89e) to head (02e138a).
Report is 22 commits behind head on main.

Files with missing lines Patch % Lines
great_tables/_formats.py 89.58% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #515      +/-   ##
==========================================
- Coverage   89.79%   89.79%   -0.01%     
==========================================
  Files          45       45              
  Lines        5382     5431      +49     
==========================================
+ Hits         4833     4877      +44     
- Misses        549      554       +5     

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

@github-actions github-actions bot temporarily deployed to pr-515 November 20, 2024 20:03 Destroyed
@github-actions github-actions bot temporarily deployed to pr-515 November 20, 2024 20:21 Destroyed
@github-actions github-actions bot temporarily deployed to pr-515 November 20, 2024 21:30 Destroyed
@github-actions github-actions bot temporarily deployed to pr-515 November 20, 2024 22:21 Destroyed
@github-actions github-actions bot temporarily deployed to pr-515 November 21, 2024 15:30 Destroyed
@github-actions github-actions bot temporarily deployed to pr-515 November 21, 2024 15:54 Destroyed
@github-actions github-actions bot temporarily deployed to pr-515 November 21, 2024 18:15 Destroyed
@github-actions github-actions bot temporarily deployed to pr-515 November 22, 2024 16:59 Destroyed
elif isinstance(self.stroke_width, (int, float)):
stroke_width = f"{str(self.stroke_width)}px"
else:
stroke_width = self.stroke_width
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please test this

Copy link
Member Author

Choose a reason for hiding this comment

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

Now tested.

if icon in self.fill_color:
fill_color = self.fill_color[icon]
else:
fill_color = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please test this

Copy link
Member Author

Choose a reason for hiding this comment

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

Tests now present for this.

Copy link
Collaborator

@machow machow left a comment

Choose a reason for hiding this comment

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

This LGTM, if we can polars data wrangling in the second example

Comment on lines 3951 to 3967
towny_mini = (
pl.from_pandas(towny)
.select(["name", "csd_type", "population_2021"])
.filter(pl.col("csd_type").is_in(["city", "town"]))
.group_by("csd_type", maintain_order=True)
.agg([
pl.col("name").sort_by("population_2021", descending=True).head(5),
pl.col("population_2021").sort(descending=True).head(5)
])
.sort("csd_type")
.explode(["name", "population_2021"])
.with_columns(
csd_type = pl.when(pl.col("csd_type") == "town")
.then(pl.lit("house-chimney"))
.otherwise(pl.lit("city"))
)
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to just select a few rows of this data. E.g. towny[[0, 3, 5], :]. Say maybe the top 2 in each of your groups. It seems easier to get into an example with less setup (a doesn't seem critical to have a comprehensive table).

Copy link
Member Author

Choose a reason for hiding this comment

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

I took your approach and the setup for the example is far simpler.

@github-actions github-actions bot temporarily deployed to pr-515 November 26, 2024 17:01 Destroyed
@github-actions github-actions bot temporarily deployed to pr-515 November 26, 2024 17:03 Destroyed
@github-actions github-actions bot temporarily deployed to pr-515 November 26, 2024 17:36 Destroyed
@github-actions github-actions bot temporarily deployed to pr-515 November 26, 2024 17:47 Destroyed
@rich-iannone rich-iannone marked this pull request as ready for review November 26, 2024 17:51
@github-actions github-actions bot temporarily deployed to pr-515 November 26, 2024 17:52 Destroyed
@rich-iannone rich-iannone requested a review from machow November 26, 2024 17:58
Copy link
Collaborator

@machow machow left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@machow machow merged commit d1571c4 into main Dec 10, 2024
13 of 14 checks passed
@rich-iannone rich-iannone deleted the feat-fmt-icon branch December 10, 2024 14:43
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.

2 participants