Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7eaac32

Browse filesBrowse files
authored
Merge pull request #24657 from larsoner/savefig
BUG: Fix bug with mutable input modification
2 parents e883f43 + 76e087d commit 7eaac32
Copy full SHA for 7eaac32

File tree

Expand file treeCollapse file tree

3 files changed

+6
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+6
-0
lines changed

‎lib/matplotlib/image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/image.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,9 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None,
16531653
rgba = sm.to_rgba(arr, bytes=True)
16541654
if pil_kwargs is None:
16551655
pil_kwargs = {}
1656+
else:
1657+
# we modify this below, so make a copy (don't modify caller's dict)
1658+
pil_kwargs = pil_kwargs.copy()
16561659
pil_shape = (rgba.shape[1], rgba.shape[0])
16571660
image = PIL.Image.frombuffer(
16581661
"RGBA", pil_shape, rgba, "raw", "RGBA", 0, 1)

‎lib/matplotlib/tests/test_agg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_agg.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,11 @@ def test_pil_kwargs_webp():
254254
buf_small = io.BytesIO()
255255
pil_kwargs_low = {"quality": 1}
256256
plt.savefig(buf_small, format="webp", pil_kwargs=pil_kwargs_low)
257+
assert len(pil_kwargs_low) == 1
257258
buf_large = io.BytesIO()
258259
pil_kwargs_high = {"quality": 100}
259260
plt.savefig(buf_large, format="webp", pil_kwargs=pil_kwargs_high)
261+
assert len(pil_kwargs_high) == 1
260262
assert buf_large.getbuffer().nbytes > buf_small.getbuffer().nbytes
261263

262264

‎lib/matplotlib/tests/test_image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_image.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ def test_imsave_pil_kwargs_tiff():
249249
buf = io.BytesIO()
250250
pil_kwargs = {"description": "test image"}
251251
plt.imsave(buf, [[0, 1], [2, 3]], format="tiff", pil_kwargs=pil_kwargs)
252+
assert len(pil_kwargs) == 1
252253
im = Image.open(buf)
253254
tags = {TAGS[k].name: v for k, v in im.tag_v2.items()}
254255
assert tags["ImageDescription"] == "test image"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.