8000 BUG: Fix bug with mutable input modification by larsoner · Pull Request #24657 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix bug with mutable input modification #24657

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

Merged
merged 1 commit into from
Dec 7, 2022
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
F 8000 ailed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,9 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None,
rgba = sm.to_rgba(arr, bytes=True)
if pil_kwargs is None:
pil_kwargs = {}
else:
# we modify this below, so make a copy (don't modify caller's dict)
pil_kwargs = pil_kwargs.copy()
pil_shape = (rgba.shape[1], rgba.shape[0])
image = PIL.Image.frombuffer(
"RGBA", pil_shape, rgba, "raw", "RGBA", 0, 1)
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/tests/test_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,11 @@ def test_pil_kwargs_webp():
buf_small = io.BytesIO()
pil_kwargs_low = {"quality": 1}
plt.savefig(buf_small, format="webp", pil_kwargs=pil_kwargs_low)
assert len(pil_kwargs_low) == 1
buf_large = io.BytesIO()
pil_kwargs_high = {"quality": 100}
plt.savefig(buf_large, format="webp", pil_kwargs=pil_kwargs_high)
assert len(pil_kwargs_high) == 1
assert buf_large.getbuffer().nbytes > buf_small.getbuffer().nbytes


Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def test_imsave_pil_kwargs_tiff():
buf = io.BytesIO()
pil_kwargs = {"description": "test image"}
plt.imsave(buf, [[0, 1], [2, 3]], format="tiff", pil_kwargs=pil_kwargs)
assert len(pil_kwargs) == 1
im = Image.open(buf)
tags = {TAGS[k].name: v for k, v in im.tag_v2.items()}
assert tags["ImageDescription"] == "test image"
Expand Down
0