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

Fix bug in Graph.remove_vertex(vs) when vs is an iterable

parent 0da3e441
Pipeline #38 passed with stage
......@@ -933,6 +933,7 @@ void export_python_interface()
def("add_vertex", graph_tool::add_vertex);
def("add_edge", graph_tool::add_edge);
def("remove_vertex", graph_tool::remove_vertex);
def("remove_vertex_array", graph_tool::remove_vertex_array);
def("clear_vertex", graph_tool::clear_vertex);
def("remove_edge", graph_tool::remove_edge);
def("add_edge_list", graph_tool::do_add_edge_list);
......
......@@ -1815,26 +1815,26 @@ class Graph(object):
the graph will no longer be the same.
"""
try:
vs = numpy.array([int(vertex)], dtype="int64")
except TypeError:
back = self.__graph.get_num_vertices(False) - 1
is_iter = isinstance(vertex, collections.Iterable)
if is_iter:
try:
vs = numpy.asarray(vertex, dtype="int64")
except TypeError:
vs = numpy.asarray([int(v) for v in vertex], dtype="int64")
if len(vs) == 0:
return
vs = numpy.sort(vs)[::-1]
back = self.__graph.get_num_vertices(False) - 1
if vs.max() > back:
raise ValueError("Vertex index %d is invalid" % vs.max())
vmax = vs[0]
if vs[0] > back:
raise ValueError("Vertex index %d is invalid" % vs[0])
else:
vmax = int(vertex)
# move / shift all known property maps
if len(vs) > 0 or vs[0] != back:
if vmax != back:
if not is_iter:
vs = numpy.asarray((vertex,), dtype="int64")
for pmap in self.__known_properties.values():
if pmap() is not None and pmap().key_type() == "v" and pmap().is_writable():
if fast:
......@@ -1842,7 +1842,10 @@ class Graph(object):
else:
self.__graph.shift_vertex_property(pmap()._PropertyMap__map.get_map(), vs)
libcore.remove_vertex(self.__graph, vs, fast)
if is_iter:
libcore.remove_vertex_array(self.__graph, vs, fast)
else:
libcore.remove_vertex(self.__graph, vertex, fast)
def clear_vertex(self, vertex):
"""Remove all in and out-edges from the given vertex."""
......
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