Skip to content

Commit a31725e

Browse files
Switch to using more performant/preferred lookup call
1 parent f885a30 commit a31725e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

gerrychain/tree.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def bipartition_tree(
201201
tree is not provided
202202
:param choice: :func:`random.choice`. Can be substituted for testing.
203203
"""
204-
populations = {node: graph.nodes[node][pop_col] for node in graph.node_indicies}
204+
populations = {node: graph.lookup(node, pop_col) for node in graph.node_indicies}
205205

206206
possible_cuts = []
207207
if spanning_tree is None:
@@ -231,7 +231,7 @@ def _bipartition_tree_random_all(
231231
choice=random.choice,
232232
):
233233
"""Randomly bipartitions a graph and returns all cuts."""
234-
populations = {node: graph.nodes[node][pop_col] for node in graph.node_indicies}
234+
populations = {node: graph.lookup(node, pop_col) for node in graph.node_indicies}
235235

236236
possible_cuts = []
237237
if spanning_tree is None:
@@ -342,7 +342,7 @@ def recursive_tree_part(
342342
part_pop = 0
343343
for node in nodes:
344344
flips[node] = part
345-
part_pop += graph.nodes[node][pop_col]
345+
part_pop += graph.lookup(node, pop_col)
346346
debt += part_pop - pop_target
347347
remaining_nodes -= nodes
348348

@@ -385,7 +385,7 @@ def get_seed_chunks(
385385

386386
chunk_pop = 0
387387
for node in graph.node_indicies:
388-
chunk_pop += graph.nodes[node][pop_col]
388+
chunk_pop += graph.lookup(node, pop_col)
389389

390390
while True:
391391
epsilon = abs(epsilon)
@@ -425,7 +425,7 @@ def get_seed_chunks(
425425

426426
part_pop = 0
427427
for node in remaining_nodes:
428-
part_pop += graph.nodes[node][pop_col]
428+
part_pop += graph.lookup(node, pop_col)
429429
part_pop_as_dist = part_pop / num_chunks_left
430430
fake_epsilon = epsilon
431431
if num_chunks_left != 1:

0 commit comments

Comments
 (0)