Skip to content

Commit b7669cc

Browse files
committed
add: py files without formatting for check
1 parent 178bde6 commit b7669cc

3 files changed

Lines changed: 129 additions & 43 deletions

File tree

src/igraph/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
igraph library.
33
"""
44

5+
56
__license__ = """
67
Copyright (C) 2006- The igraph development team
78
@@ -941,12 +942,18 @@ def Incidence(cls, *args, **kwds):
941942

942943
def are_connected(self, *args, **kwds):
943944
"""Deprecated alias to L{Graph.are_adjacent()}."""
944-
deprecated("Graph.are_connected() is deprecated; use Graph.are_adjacent() " "instead")
945+
deprecated(
946+
"Graph.are_connected() is deprecated; use Graph.are_adjacent() "
947+
"instead"
948+
)
945949
return self.are_adjacent(*args, **kwds)
946950

947951
def get_incidence(self, *args, **kwds):
948952
"""Deprecated alias to L{Graph.get_biadjacency()}."""
949-
deprecated("Graph.get_incidence() is deprecated; use Graph.get_biadjacency() " "instead")
953+
deprecated(
954+
"Graph.get_incidence() is deprecated; use Graph.get_biadjacency() "
955+
"instead"
956+
)
950957
return self.get_biadjacency(*args, **kwds)
951958

952959

@@ -977,7 +984,9 @@ def get_incidence(self, *args, **kwds):
977984

978985
##############################################################
979986
# Adding aliases for the 3D versions of the layout methods
980-
Graph.layout_fruchterman_reingold_3d = _3d_version_for(Graph.layout_fruchterman_reingold)
987+
Graph.layout_fruchterman_reingold_3d = _3d_version_for(
988+
Graph.layout_fruchterman_reingold
989+
)
981990
Graph.layout_kamada_kawai_3d = _3d_version_for(Graph.layout_kamada_kawai)
982991
Graph.layout_random_3d = _3d_version_for(Graph.layout_random)
983992
Graph.layout_grid_3d = _3d_version_for(Graph.layout_grid)
@@ -1245,4 +1254,4 @@ def write(graph, filename, *args, **kwds):
12451254
"TREE_OUT",
12461255
"TREE_UNDIRECTED",
12471256
"WEAK",
1248-
)
1257+
)

src/igraph/community.py

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ def _community_fastgreedy(graph, weights=None):
2424
"""
2525
merges, qs = GraphBase.community_fastgreedy(graph, weights)
2626
optimal_count = _optimal_cluster_count_from_merges_and_modularity(graph, merges, qs)
27-
return VertexDendrogram(graph, merges, optimal_count, modularity_params={"weights": weights})
27+
return VertexDendrogram(
28+
graph, merges, optimal_count, modularity_params={"weights": weights}
29+
)
2830

2931

3032
def _community_infomap(graph, edge_weights=None, vertex_weights=None, trials=10):
@@ -51,7 +53,9 @@ def _community_infomap(graph, edge_weights=None, vertex_weights=None, trials=10)
5153
called C{codelength} that stores the code length determined by the
5254
algorithm.
5355
"""
54-
membership, codelength = GraphBase.community_infomap(graph, edge_weights, vertex_weights, trials)
56+
membership, codelength = GraphBase.community_infomap(
57+
graph, edge_weights, vertex_weights, trials
58+
)
5559
return VertexClustering(
5660
graph,
5761
membership,
@@ -60,7 +64,9 @@ def _community_infomap(graph, edge_weights=None, vertex_weights=None, trials=10)
6064
)
6165

6266

63-
def _community_leading_eigenvector(graph, clusters=None, weights=None, arpack_options=None):
67+
def _community_leading_eigenvector(
68+
graph, clusters=None, weights=None, arpack_options=None
69+
):
6470
"""Newman's leading eigenvector method for detecting community structure.
6571
6672
This is the proper implementation of the recursive, divisive algorithm:
@@ -179,13 +185,21 @@ def _community_multilevel(graph, weights=None, return_levels=False, resolution=1
179185

180186
modularity_params = {"weights": weights, "resolution": resolution}
181187
if return_levels:
182-
levels, qs = GraphBase.community_multilevel(graph, weights, return_levels=True, resolution=resolution)
188+
levels, qs = GraphBase.community_multilevel(
189+
graph, weights, return_levels=True, resolution=resolution
190+
)
183191
result = []
184192
for level, q in zip(levels, qs):
185-
result.append(VertexClustering(graph, level, q, modularity_params=modularity_params))
193+
result.append(
194+
VertexClustering(graph, level, q, modularity_params=modularity_params)
195+
)
186196
else:
187-
membership = GraphBase.community_multilevel(graph, weights, return_levels=False, resolution=resolution)
188-
result = VertexClustering(graph, membership, modularity_params=modularity_params)
197+
membership = GraphBase.community_multilevel(
198+
graph, weights, return_levels=False, resolution=resolution
199+
)
200+
result = VertexClustering(
201+
graph, membership, modularity_params=modularity_params
202+
)
189203

190204
return result
191205

@@ -203,7 +217,9 @@ def _community_optimal_modularity(graph, *args, **kwds):
203217
204218
@return: the calculated membership vector and the corresponding
205219
modularity in a tuple."""
206-
membership, modularity = GraphBase.community_optimal_modularity(graph, *args, **kwds)
220+
membership, modularity = GraphBase.community_optimal_modularity(
221+
graph, *args, **kwds
222+
)
207223
return VertexClustering(graph, membership, modularity)
208224

209225

@@ -236,11 +252,15 @@ def _community_edge_betweenness(graph, clusters=None, directed=True, weights=Non
236252
merges, qs = GraphBase.community_edge_betweenness(graph, directed, weights)
237253
if clusters is None:
238254
if qs is not None:
239-
clusters = _optimal_cluster_count_from_merges_and_modularity(graph, merges, qs)
255+
clusters = _optimal_cluster_count_from_merges_and_modularity(
256+
graph, merges, qs
257+
)
240258
else:
241259
clusters = 1
242260

243-
return VertexDendrogram(graph, merges, clusters, modularity_params={"weights": weights})
261+
return VertexDendrogram(
262+
graph, merges, clusters, modularity_params={"weights": weights}
263+
)
244264

245265

246266
def _community_spinglass(graph, *args, **kwds):
@@ -320,7 +340,9 @@ def _community_walktrap(graph, weights=None, steps=4):
320340
"""
321341
merges, qs = GraphBase.community_walktrap(graph, weights, steps)
322342
optimal_count = _optimal_cluster_count_from_merges_and_modularity(graph, merges, qs)
323-
return VertexDendrogram(graph, merges, optimal_count, modularity_params={"weights": weights})
343+
return VertexDendrogram(
344+
graph, merges, optimal_count, modularity_params={"weights": weights}
345+
)
324346

325347

326348
def _k_core(graph, *args):
@@ -370,7 +392,7 @@ def _community_leiden(
370392
initial_membership=None,
371393
n_iterations=2,
372394
node_weights=None,
373-
**kwds,
395+
**kwds
374396
):
375397
"""Finds the community structure of the graph using the Leiden
376398
algorithm of Traag, van Eck & Waltman.
@@ -408,7 +430,10 @@ def _community_leiden(
408430
raise ValueError('objective_function must be "CPM" or "modularity".')
409431

410432
if "resolution_parameter" in kwds:
411-
deprecated("resolution_parameter keyword argument is deprecated, use " "resolution=... instead")
433+
deprecated(
434+
"resolution_parameter keyword argument is deprecated, use "
435+
"resolution=... instead"
436+
)
412437
resolution = kwds.pop("resolution_parameter")
413438

414439
if kwds:
@@ -431,7 +456,9 @@ def _community_leiden(
431456
if weights is not None:
432457
modularity_params["weights"] = weights
433458

434-
return VertexClustering(graph, membership, params=params, modularity_params=modularity_params)
459+
return VertexClustering(
460+
graph, membership, params=params, modularity_params=modularity_params
461+
)
435462

436463

437464
def _community_voronoi(graph, lengths=None, weights=None, mode="all", radius=None):
@@ -492,7 +519,7 @@ def _community_voronoi(graph, lengths=None, weights=None, mode="all", radius=Non
492519

493520
clustering.generators = generators
494521
return clustering
495-
522+
496523

497524
def _modularity(self, membership, weights=None, resolution=1, directed=True):
498525
"""Calculates the modularity score of the graph with respect to a given
@@ -532,7 +559,9 @@ def _modularity(self, membership, weights=None, resolution=1, directed=True):
532559
if isinstance(membership, VertexClustering):
533560
if membership.graph != self:
534561
raise ValueError("clustering object belongs to another graph")
535-
return GraphBase.modularity(self, membership.membership, weights, resolution, directed)
562+
return GraphBase.modularity(
563+
self, membership.membership, weights, resolution, directed
564+
)
536565
else:
537566
return GraphBase.modularity(self, membership, weights, resolution, directed)
538567

0 commit comments

Comments
 (0)