File tree 2 files changed +17
-16
lines changed
2 files changed +17
-16
lines changed Original file line number Diff line number Diff line change
1
+ import copy
1
2
from datetime import datetime
2
3
import io
3
4
from pathlib import Path
@@ -1226,3 +1227,19 @@ def test_kwargs_pass():
1226
1227
1227
1228
assert fig .get_label () == 'whole Figure'
1228
1229
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'
Original file line number Diff line number Diff line change @@ -151,22 +151,6 @@ def __copy__(self):
151
151
other .set_children (val ) # val == getattr(other, key)
152
152
return other
153
153
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
-
170
154
def invalidate (self ):
171
155
"""
172
156
Invalidate this `TransformNode` and triggers an invalidation of its
You can’t perform that action at this time.
0 commit comments