Skip to content

Handle property maps of length 0 in prop_to_size and clarify its documentation

Alex Henrie requested to merge alex.henrie/graph-tool:prop_to_size into master

I'm generating a lot of graphs automatically, and occasionally one of the graphs has no vertices or edges. The prop_to_size function should gracefully handle that case and not raise an exception.

Test program:

from graph_tool import Graph
from graph_tool.draw import prop_to_size
g = Graph()
p = g.new_vertex_property("float")
print(prop_to_size(p))

Currently this program fails with the following error:

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    print(prop_to_size(p))
  File "/usr/lib/python3/dist-packages/graph_tool/draw/__init__.py", line 869, in prop_to_size
    delta = vals.max() - vals.min()
  File "/usr/local/lib/python3.6/dist-packages/numpy/core/_methods.py", line 39, in _amax
    return umr_maximum(a, axis, None, out, keepdims, initial, where)
ValueError: zero-size array to reduction operation maximum which has no identity

Merge request reports