Skip to content

Commit 5944f38

Browse files
Fix linter issues
1 parent 384b239 commit 5944f38

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

gerrychain/graph/graph.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,12 @@ class FrozenGraph:
351351
"networkx_retworkx_mapping"
352352
]
353353

354-
def __init__(self, graph: Graph, pygraph: retworkx.PyGraph = None, mappings: Tuple[dict, dict] = None):
354+
def __init__(
355+
self,
356+
graph: Graph,
357+
pygraph: retworkx.PyGraph = None,
358+
mappings: Tuple[dict, dict] = None
359+
):
355360
self.graph = networkx.classes.function.freeze(graph)
356361
self.graph.join = frozen
357362
self.graph.add_data = frozen
@@ -366,8 +371,12 @@ def __init__(self, graph: Graph, pygraph: retworkx.PyGraph = None, mappings: Tup
366371
if mappings:
367372
self.retworkx_networkx_mapping, self.networkx_retworkx_mapping = mappings
368373
else:
369-
self.retworkx_networkx_mapping = {node: self.pygraph[node]["__networkx_node__"] for node in self.pygraph.node_indexes()}
370-
self.networkx_retworkx_mapping = {self.pygraph[node]["__networkx_node__"]: node for node in self.pygraph.node_indexes()}
374+
self.retworkx_networkx_mapping = {
375+
n: self.pygraph[n]["__networkx_node__"] for n in self.pygraph.node_indexes()
376+
}
377+
self.networkx_retworkx_mapping = {
378+
self.pygraph[n]["__networkx_node__"]: n for n in self.pygraph.node_indexes()
379+
}
371380

372381
def __len__(self):
373382
return self.size
@@ -405,7 +414,8 @@ def lookup(self, node, field):
405414
return self.graph.nodes[node][field]
406415

407416
def subgraph(self, nodes):
408-
return FrozenGraph(self.graph.subgraph(nodes),
417+
return FrozenGraph(
418+
self.graph.subgraph(nodes),
409419
self.pygraph.subgraph(
410420
[self.networkx_retworkx_mapping[x] for x in nodes]
411421
)

gerrychain/proposals/tree_proposals.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from functools import partial
2-
from ..random import random
32

3+
from ..random import random
44
from ..tree import (
5-
recursive_tree_part, bipartition_tree, bipartition_tree_random,
5+
bipartition_tree_random,
66
_bipartition_tree_random_all, uniform_spanning_tree,
77
find_balanced_edge_cuts_memoization, bipartition_tree_retworkx
8+
# recursive_tree_part, bipartition_tree,
89
)
910

1011

gerrychain/tree.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,13 @@ def bipartition_tree_retworkx(
183183
):
184184
pops = graph.pygraph_pop_lookup(pop_col)
185185

186-
balanced_node_choices = retworkx.bipartition_tree(graph.pygraph, lambda x: random.random(), pops, float(pop_target), float(epsilon))
186+
balanced_node_choices = retworkx.bipartition_tree(
187+
graph.pygraph,
188+
lambda x: random.random(),
189+
pops,
190+
float(pop_target),
191+
float(epsilon)
192+
)
187193
balanced_nodes = {graph.retworkx_networkx_mapping[x] for x in choice(balanced_node_choices)[1]}
188194
return (balanced_nodes, graph.node_indices - balanced_nodes)
189195

0 commit comments

Comments
 (0)