@@ -89,15 +89,15 @@ def __init__(self, graph, index):
89
89
self .num_edges = graph .number_of_edges ()
90
90
91
91
if self .num_edges == 0 :
92
- raise ValueError ("Cannot create a graph partition of only " \
93
- "if graph has no edges/connections " )
92
+ raise ValueError ("Cannot create a graph partition " \
93
+ "if graph has no edges" )
94
94
95
95
# Store the nodes as a set of contiguous integers (indices into
96
96
#the adjacency_matrix), needed for many operations
97
97
self ._node_set = set (range (self .num_nodes ))
98
98
self ._node_names = graph .nodes ()
99
99
## raise useful error if index is missing nodes in graph
100
- self ._check_allnodes_in_index (graph )
100
+ self ._check_allnodes_in_index ()
101
101
102
102
# Now, build the edge information used in modularity computations
103
103
self .mod_e , self .mod_a = self ._edge_info ()
@@ -117,16 +117,13 @@ def _check_index_contains_sets(self):
117
117
if not all ([ x == type (set ()) for x in index_types ]):
118
118
raise TypeError ('index values should be of type set():: %s' % (index_types ))
119
119
120
- def _check_allnodes_in_index (self , graph ):
120
+ def _check_allnodes_in_index (self ):
121
121
"""Check that index contains all nodes in graph"""
122
122
sets = self .index .values ()
123
- all = []
124
- for item in sets :
125
- all += list (item )
126
- if not sorted (all ) == sorted (self ._node_set ):
127
- missing = [x for x in all if not x in self ._node_set ]
128
- raise ValueError ('index does not contain all nodes: missing %s' % missing )
129
-
123
+ indexnodes = set .union (* sets )
124
+ missing = self ._node_set .difference (indexnodes )
125
+ if missing :
126
+ raise ValueError ('index does not contain all graph nodes: missing %s' % missing )
130
127
131
128
def _edge_info (self , mod_e = None , mod_a = None , index = None ):
132
129
"""Create the vectors of edge information.
@@ -619,7 +616,7 @@ def index_as_node_names(self):
619
616
This will return the index (partition) using the graph node names"""
620
617
named_part = []
621
618
for nmod , part in self .index .iteritems ():
622
- named_part .append ([self ._node_names [x ] for x in part ])
619
+ named_part .append ( [self ._node_names [x ] for x in part ] )
623
620
return named_part
624
621
625
622
def check_integrity (self , partition ):
0 commit comments