Description
What is the feature or improvement you would like to see?
Currently, if the number of nodes / edges do not match the length of the list defining an attribute during graph initialization or add_vertices / add_edges, the list is truncated or propagated. I think throwing an error when the length of the list defining the attributes do not match the number of nodes / edges being imported would be helpful. This would also be consistent with the documentation for methods that has an attribute
parameter:
the attributes of the vertices as a dictionary. The keys of the dictionary must be the names of the attributes; the values must be iterables with exactly n items where n is the number of vertices.
the attributes of the edges as a dictionary. The keys of the dictionary must be the names of the attributes; the values must be iterables with exactly m items where m is the number of edges.
dict of sequences, all of length equal to the number of vertices to be added, containing the attributes of the new vertices. If n is a string (so a single vertex is added), then the values of this dict are the attributes themselves, but if n=1 then they have to be lists of length 1
dict of sequences, all of length equal to the number of edges to be added, containing the attributes of the new edges.
Sample below for current behaviour:
import igraph as ig
g = ig.Graph()
g.add_vertices(3, attributes={'weight' : [1,2], 'name' : ['a']})
list(g.vs)
[igraph.Vertex(<igraph.Graph object at 0x7890c1d6d040>, 0, {'weight': 1, 'name': 'a'}),
igraph.Vertex(<igraph.Graph object at 0x7890c1d6d040>, 1, {'weight': 2, 'name': 'a'}),
igraph.Vertex(<igraph.Graph object at 0x7890c1d6d040>, 2, {'weight': 1, 'name': 'a'})]
Use cases for the feature
Explain when and for what purpose the feature would be useful.
To help avoid silent bugs due to API silently propagating or truncating attributes when adding nodes / edges.