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

GT.save() saves only to .png file #593

Open
2 tasks done
SamuMazzi opened this issue Jan 30, 2025 · 1 comment
Open
2 tasks done

GT.save() saves only to .png file #593

SamuMazzi opened this issue Jan 30, 2025 · 1 comment

Comments

@SamuMazzi
Copy link

Prework

Description

In the documentation is stated

file
The name of the file to save the image to. Accepts names ending with .png, .bmp, and other
image extensions. Also accepts the extension .pdf.

but actually right now any format that will be insterted when saving the table to file will be replaced by .png extension. This is probably related to #499 which edited these lines:

  -  if not Path(file).suffix:
  -     file += ".png"
  +  file = str(Path(file).with_suffix(".png"))

with the problem that .with_suffix always put the desired extension.

I can also create a PR. It seems a pretty straightforward fix, but I'd like to have a confirmation about this bug, thanks.

Reproducible example

from great_tables import GT
from great_tables.data import sp500

# Define the start and end dates for the data range
start_date = "2010-06-07"
end_date = "2010-06-14"

# Filter sp500 using Pandas to dates between `start_date` and `end_date`
sp500_mini = sp500[(sp500["date"] >= start_date) & (sp500["date"] <= end_date)]

# Create a gt table based on the `sp500_mini` table data
table = (
    GT(sp500_mini)
    .tab_header(title="S&P 500", subtitle=f"{start_date} to {end_date}")
    .fmt_currency(columns=["open", "high", "low", "close"])
    .fmt_date(columns="date", date_style="wd_m_day_year")
    .fmt_number(columns="volume", compact=True)
    .cols_hide(columns="adj_close")
)

table.save("sp500_mini.pdf")

You'll see a file sp500_mini.png

Expected result

It should have saved a file named sp500_mini.pdf

Development environment

  • Operating System: Linux, Ubuntu 24.04
  • great_tables Version: 0.16.1
@jrycw
Copy link
Collaborator

jrycw commented Jan 30, 2025

@SamuMazzi , thanks so much for reporting this.

For now, at least two bugs need to be fixed:

@machow and @rich-iannone, could you help address these issues? GT.save() is a crucial function in our library. (Apologies for the potential bugs—I'm currently on Chinese New Year holiday and may have limited access to a computer.)

0x64746b added a commit to 0x64746b/x332-target-speeds that referenced this issue Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants