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 191452d

Browse filesBrowse files
committed
Improved implementation of Path.copy and deepcopy
The original Path.copy raised RecursionError, new implementation mimicks deepcopy, creating shared members. Path tests were updated to utilize member functions copy and deepcopy instead of builtin copy functional protocol.
1 parent 01a1c49 commit 191452d
Copy full SHA for 191452d

File tree

Expand file treeCollapse file tree

2 files changed

+29
-5
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+29
-5
lines changed

‎lib/matplotlib/path.py

Copy file name to clipboardExpand all lines: lib/matplotlib/path.py
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,13 @@ def __copy__(self):
264264
Return a shallow copy of the `Path`, which will share the
265265
vertices and codes with the source `Path`.
266266
"""
267-
import copy
268-
return copy.copy(self)
267+
try:
268+
codes = self.codes
269+
except AttributeError:
270+
codes = None
271+
return self.__class__(
272+
self.vertices, codes,
273+
_interpolation_steps=self._interpolation_steps)
269274

270275
copy = __copy__
271276

‎lib/matplotlib/tests/test_path.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_path.py
+22-3Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import copy
21
import re
32

43
import numpy as np
@@ -333,8 +332,28 @@ def test_path_deepcopy():
333332
codes = [Path.MOVETO, Path.LINETO]
334333
path1 = Path(verts)
335334
path2 = Path(verts, codes)
336-
copy.deepcopy(path1)
337-
copy.deepcopy(path2)
335+
path1_copy = path1.deepcopy()
336+
path2_copy = path2.deepcopy()
337+
assert(path1 is not path1_copy)
338+
assert(path1.vertices is not path1_copy.vertices)
339+
assert(path2 is not path2_copy)
340+
assert(path2.vertices is not path2_copy.vertices)
341+
assert(path2.codes is not path2_copy.codes)
342+
343+
344+
def test_path_shallowcopy():
345+
# Should not raise any error
346+
verts = [[0, 0], [1, 1]]
347+
codes = [Path.MOVETO, Path.LINETO]
348+
path1 = Path(verts)
349+
path2 = Path(verts, codes)
350+
path1_copy = path1.copy()
351+
path2_copy = path2.copy()
352+
assert(path1 is not path1_copy)
353+
assert(path1.vertices is path1_copy.vertices)
354+
assert(path2 is not path2_copy)
355+
assert(path2.vertices is path2_copy.vertices)
356+
assert(path2.codes is path2_copy.codes)
338357

339358

340359
@pytest.mark.parametrize('phi', np.concatenate([

0 commit comments

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