Skip to content

Commit 4b35367

Browse files
author
CindeeM
committed
RF: clean up doc strings, add exception to try,except, PEP8
1 parent c1ef9da commit 4b35367

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

brainx/weighted_modularity.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,35 @@
88

99

1010
class Partition:
11+
"""Represent a weighted Graph Partition
12+
13+
The main object keeping track of the nodes in each partition is the
14+
community attribute.
15+
"""
1116
def __init__(self, graph, community=None):
1217
""" initialize partition of graph, with optional community
13-
defined
1418
1519
Parameters
1620
==========
1721
graph : networkx graph
22+
1823
community : list of sets
1924
a list of sets with nodes in each set
2025
if community is None, will initialize with
2126
one community per node
2227
"""
23-
# make sure graph has edge weights, even if binary, and no neg weights
28+
# assert graph has edge weights, and no negative weights
2429
mat = nx.adjacency_matrix(graph)
2530
if mat.min() < 0:
26-
raise ValueError('Graph has invalid neg weights')
31+
raise ValueError('Graph has invalid negative weights')
2732

2833
self.graph = nx.from_numpy_matrix(mat)
2934
if community is None:
3035
self._community = self._init_communities_from_nodes()
3136
else:
3237
self.set_community(community)
3338
self.total_edge_weight = graph.size(weight='weight')
34-
self.degrees = graph.degree(weight = 'weight')
39+
self.degrees = graph.degree(weight='weight')
3540

3641
@property
3742
def community(self):
@@ -157,7 +162,7 @@ def meta_graph(partition):
157162
node2_community = partition.get_node_community(node2)
158163
try:
159164
tmpw = metagraph[node1_community][node2_community]['weight']
160-
except:
165+
except KeyError:
161166
tmpw = 0
162167
metagraph.add_edge(
163168
node1_community,
@@ -174,7 +179,6 @@ def _communities_without_node(part, node):
174179
newpart = copy.deepcopy(part.community)
175180
newpart[node_comm].remove(node)
176181
return newpart
177-
mmunity_nodes_self
178182

179183

180184
def _community_nodes_alledgesw(part, removed_node):

0 commit comments

Comments
 (0)