8000 Merge pull request #6877 from has2k1/fix-deepcopy · matplotlib/matplotlib@b338a71 · GitHub
[go: up one dir, main page]

Skip to content

Commit b338a71

Browse files
committed
Merge pull request #6877 from has2k1/fix-deepcopy
FIX: Path deepcopy signature
1 parent c5d7b60 commit b338a71

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/matplotlib/path.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,17 @@ def __copy__(self):
298298

299299
copy = __copy__
300300

301-
def __deepcopy__(self):
301+
def __deepcopy__(self, memo=None):
302302
"""
303303
Returns a deepcopy of the `Path`. The `Path` will not be
304304
readonly, even if the source `Path` is.
305305
"""
306+
try:
307+
codes = self.codes.copy()
308+
except AttributeError:
309+
codes = None
306310
return self.__class__(
307-
self.vertices.copy(), self.codes.copy(),
311+
self.vertices.copy(), codes,
308312
_interpolation_steps=self._interpolation_steps)
309313

310314
deepcopy = __deepcopy__

lib/matplotlib/tests/test_path.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
3+
import copy
34

45
import six
56

@@ -172,6 +173,16 @@ def test_path_to_polygons():
172173
assert_array_equal(p.to_polygons(closed_only=False), [data])
173174

174175

176+
def test_path_deepcopy():
177+
# Should not raise any error
178+
verts = [[0, 0], [1, 1]]
179+
codes = [Path.MOVETO, Path.LINETO]
180+
path1 = Path(verts)
181+
path2 = Path(verts, codes)
182+
copy.deepcopy(path1)
183+
copy.deepcopy(path2)
184+
185+
175186
if __name__ == '__main__':
176187
import nose
177188
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)
0