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

FIX: do not mutate dictionaries passed in by user #24229

Merged
merged 1 commit into from Oct 20, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/matplotlib/figure.py
Expand Up @@ -878,8 +878,7 @@ def subplots(self, nrows=1, ncols=1, *, sharex=False, sharey=False,
# Note that this is the same as
fig.subplots(2, 2, sharex=True, sharey=True)
"""
if gridspec_kw is None:
gridspec_kw = {}
gridspec_kw = dict(gridspec_kw or {})
if height_ratios is not None:
if 'height_ratios' in gridspec_kw:
raise ValueError("'height_ratios' must not be defined both as "
Expand Down Expand Up @@ -1869,7 +1868,7 @@ def subplot_mosaic(self, mosaic, *, sharex=False, sharey=False,

"""
subplot_kw = subplot_kw or {}
gridspec_kw = gridspec_kw or {}
gridspec_kw = dict(gridspec_kw or {})
if height_ratios is not None:
if 'height_ratios' in gridspec_kw:
raise ValueError("'height_ratios' must not be defined both as "
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_figure.py
Expand Up @@ -1412,3 +1412,11 @@ def test_unpickle_with_device_pixel_ratio():
assert fig.dpi == 42*7
fig2 = pickle.loads(pickle.dumps(fig))
assert fig2.dpi == 42


def test_gridspec_no_mutate_input():
gs = {'left': .1}
gs_orig = dict(gs)
plt.subplots(1, 2, width_ratios=[1, 2], gridspec_kw=gs)
assert gs == gs_orig
plt.subplot_mosaic('AB', width_ratios=[1, 2], gridspec_kw=gs)