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: Allow spanners to use units notation in .tab_spanner() #393

Merged
merged 6 commits into from
Jul 8, 2024

Conversation

rich-iannone
Copy link
Member

This PR allows for the use of units notation text in spanner labels (through .tab_spanner()). Here is an example of the intended usage:

from great_tables import GT, md, system_fonts
from great_tables.data import reactions
import polars as pl
import polars.selectors as ps

reactions_mini = (
    pl.from_pandas(reactions)
    .filter(pl.col("cmpd_type") == "mercaptan")
    .select([
        "cmpd_name",
        "cmpd_formula",
        ps.ends_with("k298")
    ])
    .with_columns(
        cmpd_formula=pl.concat_str(
            "%" + pl.col("cmpd_formula") + "%"
        )
    )
)

(
    GT(reactions_mini, rowname_col="cmpd_name")
    .tab_header(title="Gas-phase reactions \
    of selected mercaptan compounds")
    .tab_spanner(
        columns=ps.ends_with("k298"),
        label = "Reaction Rate Constant (298 K),<br>{{cm^3 molecules^–1 s^–1}}"
    )
    .fmt_units(columns="cmpd_formula")
    .fmt_scientific(columns=ps.ends_with("k298"))
    .sub_missing()
    .cols_hide(columns="O3_k298")
    .cols_label(
        cmpd_formula="",
        OH_k298="OH",
        NO3_k298="{{%NO3%}}",
        Cl_k298="Cl",
    )
    .opt_stylize(style=1, color="blue")
    .opt_horizontal_padding(scale=3)
    .tab_options(
        table_font_names=system_fonts("humanist"),
    )
)
image

Copy link

codecov bot commented Jul 8, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 4 lines in your changes missing coverage. Please review.

Project coverage is 86.43%. Comparing base (793bd2a) to head (aa219aa).

Files Patch % Lines
great_tables/_spanners.py 70.00% 3 Missing ⚠️
great_tables/_boxhead.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #393      +/-   ##
==========================================
- Coverage   86.48%   86.43%   -0.06%     
==========================================
  Files          42       42              
  Lines        4685     4696      +11     
==========================================
+ Hits         4052     4059       +7     
- Misses        633      637       +4     

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

@github-actions github-actions bot temporarily deployed to pr-393 July 8, 2024 17:28 Destroyed
@github-actions github-actions bot temporarily deployed to pr-393 July 8, 2024 17:28 Destroyed
@github-actions github-actions bot temporarily deployed to pr-393 July 8, 2024 18:38 Destroyed
@rich-iannone rich-iannone marked this pull request as ready for review July 8, 2024 20:50
@rich-iannone rich-iannone requested a review from machow July 8, 2024 20:50
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! I'll open an issue to document this behavior in tab_spanner, but want to get this tucked away!

@machow machow merged commit 8462096 into main Jul 8, 2024
11 of 13 checks passed
@machow
Copy link
Collaborator

machow commented Jul 8, 2024

#395

@rich-iannone rich-iannone deleted the feat-units-notn-spanners branch July 9, 2024 01:18
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