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_flag() method #523

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open

feat: add fmt_flag() method #523

wants to merge 25 commits into from

Conversation

rich-iannone
Copy link
Member

This adds the fmt_flag() method, which allows for the rendering of flag icons based on 2- or 3-letter country codes in table cells. The flag SVG data has been added within CSV data so there are no new dependencies with this PR.

Here's an example of the fmt_flag() method in use:

from great_tables import GT
from great_tables.data import countrypops
import polars as pl

countrypops_mini = (
    pl.from_pandas(countrypops)
    .filter(pl.col("year") == 2021)
    .filter(pl.col("country_name").str.starts_with("S"))
    .sort("country_name")
    .head(10)
    .drop(["year", "country_code_3"])
)

(
    GT(countrypops_mini)
    .fmt_integer(columns="population")
    .fmt_flag(columns="country_code_2")
    .cols_label(
        country_code_2 = "",
        country_name = "Country",
        population = "Population (2021)"
    )
    .cols_move_to_start(columns="country_code_2")
)
image

@github-actions github-actions bot temporarily deployed to pr-523 November 25, 2024 19:49 Destroyed
Copy link

codecov bot commented Nov 25, 2024

Codecov Report

Attention: Patch coverage is 87.71930% with 7 lines in your changes missing coverage. Please review.

Project coverage is 89.78%. Comparing base (925fa41) to head (ffd71b3).

Files with missing lines Patch % Lines
great_tables/_formats.py 85.41% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #523      +/-   ##
==========================================
- Coverage   89.79%   89.78%   -0.01%     
==========================================
  Files          45       45              
  Lines        5321     5376      +55     
==========================================
+ Hits         4778     4827      +49     
- Misses        543      549       +6     

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

@github-actions github-actions bot temporarily deployed to pr-523 November 25, 2024 20:25 Destroyed
@github-actions github-actions bot temporarily deployed to pr-523 November 25, 2024 20:33 Destroyed
@github-actions github-actions bot temporarily deployed to pr-523 November 25, 2024 21:24 Destroyed
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file is 1.74 MB, which is a bit large to carry around in a Python library. Is the purpose of this file so people can specify flag names in a variety of locales? I wonder if 1.74MB in order to support specification of flag names across locales is a bit heavy (could there be a separate library for translating country names in different locales?).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think a separate library might be better for this extra feature. I'll slim this down.

@github-actions github-actions bot temporarily deployed to pr-523 November 25, 2024 22:06 Destroyed
@github-actions github-actions bot temporarily deployed to pr-523 November 25, 2024 22:16 Destroyed
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