diff --git a/lib/matplotlib/path.py b/lib/matplotlib/path.py index d5b0763e7736..ead23440fa7c 100644 --- a/lib/matplotlib/path.py +++ b/lib/matplotlib/path.py @@ -297,13 +297,17 @@ def __copy__(self): copy = __copy__ - def __deepcopy__(self): + def __deepcopy__(self, memo=None): """ Returns a deepcopy of the `Path`. The `Path` will not be readonly, even if the source `Path` is. """ + try: + codes = self.codes.copy() + except AttributeError: + codes = None return self.__class__( - self.vertices.copy(), self.codes.copy(), + self.vertices.copy(), codes, _interpolation_steps=self._interpolation_steps) deepcopy = __deepcopy__ diff --git a/lib/matplotlib/tests/test_path.py b/lib/matplotlib/tests/test_path.py index 5e31a919a58a..6f1e57eed3d4 100644 --- a/lib/matplotlib/tests/test_path.py +++ b/lib/matplotlib/tests/test_path.py @@ -1,5 +1,6 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) +import copy import six @@ -172,6 +173,16 @@ def test_path_to_polygons(): assert_array_equal(p.to_polygons(closed_only=False), [data]) +def test_path_deepcopy(): + # Should not raise any error + verts = [[0, 0], [1, 1]] + codes = [Path.MOVETO, Path.LINETO] + path1 = Path(verts) + path2 = Path(verts, codes) + copy.deepcopy(path1) + copy.deepcopy(path2) + + if __name__ == '__main__': import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False)