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

Update FmtImage.to_html() #444

Merged
merged 1 commit into from
Sep 16, 2024
Merged

Update FmtImage.to_html() #444

merged 1 commit into from
Sep 16, 2024

Conversation

jrycw
Copy link
Collaborator

@jrycw jrycw commented Sep 16, 2024

Hello team,

I'd like to format the column by providing an HTTP/HTTPS URL to the path parameter in GT.fmt_image() like so:

import polars as pl
from great_tables import GT

df = pl.DataFrame({"logo": ["GT_logo.svg"]})
GT(df).fmt_image(
    "logo",
    path="https://raw.githubusercontent.com/posit-dev/great-tables/main/docs/assets/",
)

I was expecting this outcome:
image

However, I'm encountering a TypeError: sub() missing 1 required positional argument: 'string'.

It appears that the error originates from this line:

norm_path = re.sub(r"/\s+$", self.path)

If I understand correctly, this line is intended to do two things: (1) remove trailing spaces, if any, and (2) remove the trailing /, if present. To fix this, the line could be updated as follows:

norm_path = re.sub(r"/\s*$", "", self.path)

This would:

  • Pass all three required arguments to re.sub().
  • Change the + modifier to * to allow for zero or more spaces.

That said, I believe using self.path.rstrip().removesuffix("/") as proposed in this PR is more straightforward and easier to understand.

Copy link

codecov bot commented Sep 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.72%. Comparing base (016c67f) to head (8fa2fd4).
Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #444      +/-   ##
==========================================
+ Coverage   86.68%   86.72%   +0.03%     
==========================================
  Files          42       42              
  Lines        4685     4684       -1     
==========================================
+ Hits         4061     4062       +1     
+ Misses        624      622       -2     

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

@machow machow requested a review from rich-iannone September 16, 2024 14:03
@machow
Copy link
Collaborator

machow commented Sep 16, 2024

@rich-iannone do you mind taking a look? Especially on double checkingnorm_path's job there? Seems like a nice addition!

(may be useful for us to leave a note here on what would happen in the gt r package if someone used an http path)

Copy link
Member

@rich-iannone rich-iannone left a comment

Choose a reason for hiding this comment

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

LGTM!

@machow machow merged commit 0d1e1be into posit-dev:main Sep 16, 2024
13 checks passed
@jrycw jrycw deleted the update-FmtImage branch September 17, 2024 00:35
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.

3 participants