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

Figure.savefig: Support uppercase file extensions (e.g., PNG, PDF) #2697

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def savefig(

fname = Path(fname)
prefix, suffix = fname.with_suffix("").as_posix(), fname.suffix
ext = suffix[1:] # Remove the .
ext = suffix[1:].lower() # Remove the . and normalize to lowercase
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 don't update the docstrings to document this new enhancement because I don't want to encourage users to use uppercase file extensions.

Copy link
Member

@yvonnefroehlich yvonnefroehlich Sep 21, 2023

Choose a reason for hiding this comment

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

I agree that the use of upper case file extensions (including any combination of lower and upper case letters) should be avoided. Thus, I feel it is fine to not explicitly mention this possibility in the documentation.

# alias jpeg to jpg
if ext == "jpeg":
ext = "jpg"
Expand Down
8 changes: 5 additions & 3 deletions pygmt/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ def test_figure_savefig_exists():
fig = Figure()
fig.basemap(region="10/70/-300/800", projection="X3i/5i", frame="af")
prefix = "test_figure_savefig_exists"
for fmt in "png pdf jpg jpeg bmp eps tif".split():
for fmt in "png pdf jpg jpeg bmp eps tif PNG JPG JPEG Png".split():
fname = ".".join([prefix, fmt])
fig.savefig(fname)
assert os.path.exists(fname)
os.remove(fname)

fname = Path(fname)
assert fname.exists()
fname.unlink()


def test_figure_savefig_directory_nonexists():
Expand Down