Commit da569528 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Implement __copy__ and __deepcopy__ for Graph and PropertyMap

parent f2acf0b1
......@@ -518,13 +518,29 @@ class PropertyMap(object):
vals)
def copy(self, value_type=None):
"""Return a copy of the property map. If ``value_type`` is specified,
the value type is converted to the chosen type."""
"""Return a copy of the property map. If ``value_type`` is specified, the
value type is converted to the chosen type."""
return self.get_graph().copy_property(self, value_type=value_type)
def __copy__(self):
return self.copy()
def __deepcopy__(self, memo):
if self.value_type() != "python::object":
return self.copy()
else:
pmap = self.copy()
g = self.get_graph()
if self.key_type() == "g":
iters = [g]
elif self.key_type() == "v":
iters = g.vertices()
else:
iters = g.edges()
for v in iters:
pmap[v] = copy.deepcopy(self[v], memo)
return pmap
def get_graph(self):
"""Get the graph class to which the map refers."""
g = self.__g()
......@@ -1441,6 +1457,9 @@ class Graph(object):
def __copy__(self):
return self.copy()
def __deepcopy__(self, memo):
return self.copy()
def __repr__(self):
# provide more useful information
d = "directed" if self.is_directed() else "undirected"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment