Skip to content

Commit a7db8c2

Browse files
committed
FIX: Remove the deepcopy override from transforms
Let Python take care of the deepcopy for us.
1 parent 98997ee commit a7db8c2

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

lib/matplotlib/tests/test_figure.py

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import copy
12
from datetime import datetime
23
import io
34
from pathlib import Path
@@ -1226,3 +1227,19 @@ def test_kwargs_pass():
12261227

12271228
assert fig.get_label() == 'whole Figure'
12281229
assert sub_fig.get_label() == 'sub figure'
1230+
1231+
1232+
def test_deepcopy():
1233+
fig1, ax = plt.subplots()
1234+
ax.plot([0, 1], [2, 3])
1235+
ax.set_yscale('log')
1236+
1237+
fig2 = copy.deepcopy(fig1)
1238+
1239+
# Make sure it is a new object
1240+
assert fig2.axes[0] is not ax
1241+
# And that the axis scale got propagated
1242+
assert fig2.axes[0].get_yscale() == 'log'
1243+
# Update the deepcopy and check the original isn't modified
1244+
fig2.axes[0].set_yscale('linear')
1245+
assert ax.get_yscale() == 'log'

lib/matplotlib/transforms.py

-16
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,6 @@ def __copy__(self):
151151
other.set_children(val) # val == getattr(other, key)
152152
return other
153153

154-
def __deepcopy__(self, memo):
155-
# We could deepcopy the entire transform tree, but nothing except
156-
# `self` is accessible publicly, so we may as well just freeze `self`.
157-
other = self.frozen()
158-
if other is not self:
159-
return other
160-
# Some classes implement frozen() as returning self, which is not
161-
# acceptable for deepcopying, so we need to handle them separately.
162-
other = copy.deepcopy(super(), memo)
163-
# If `c = a + b; a1 = copy(a)`, then modifications to `a1` do not
164-
# propagate back to `c`, i.e. we need to clear the parents of `a1`.
165-
other._parents = {}
166-
# If `c = a + b; c1 = copy(c)`, this creates a separate tree
167-
# (`c1 = a1 + b1`) so nothing needs to be done.
168-
return other
169-
170154
def invalidate(self):
171155
"""
172156
Invalidate this `TransformNode` and triggers an invalidation of its

0 commit comments

Comments
 (0)