From e2ef12b926e30d0cc02d3e6bbcc9f18cd3d61983 Mon Sep 17 00:00:00 2001 From: Chris Donnay Date: Wed, 11 Oct 2023 12:44:57 -0400 Subject: [PATCH 1/4] error handling for single callable constraint --- gerrychain/chain.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gerrychain/chain.py b/gerrychain/chain.py index 156979aa..880a90dc 100644 --- a/gerrychain/chain.py +++ b/gerrychain/chain.py @@ -41,10 +41,10 @@ def __init__( """ if callable(constraints): - is_valid = constraints + is_valid = Validator([constraints]) else: is_valid = Validator(constraints) - + if not is_valid(initial_state): failed = [ constraint From 558ebb74aa53ab947cf6e950858d7a342e13bc45 Mon Sep 17 00:00:00 2001 From: Chris Donnay Date: Wed, 11 Oct 2023 14:47:58 -0400 Subject: [PATCH 2/4] fix population imbalance error --- gerrychain/tree.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gerrychain/tree.py b/gerrychain/tree.py index 1d4f872d..fed5134f 100644 --- a/gerrychain/tree.py +++ b/gerrychain/tree.py @@ -374,11 +374,13 @@ def recursive_tree_part( for part in parts[:-1]: min_pop = max(pop_target * (1 - epsilon), pop_target * (1 - epsilon) - debt) max_pop = min(pop_target * (1 + epsilon), pop_target * (1 + epsilon) - debt) + new_pop_target = (min_pop + max_pop) / 2 + nodes = method( graph.subgraph(remaining_nodes), pop_col=pop_col, - pop_target=(min_pop + max_pop) / 2, - epsilon=(max_pop - min_pop) / (2 * pop_target), + pop_target=new_pop_target, + epsilon=(max_pop - min_pop) / (2 * new_pop_target), node_repeats=node_repeats, ) @@ -389,6 +391,7 @@ def recursive_tree_part( for node in nodes: flips[node] = part part_pop += graph.nodes[node][pop_col] + debt += part_pop - pop_target remaining_nodes -= nodes From e747897a65a87ed7e7fbfe1e36c7b174afcdf955 Mon Sep 17 00:00:00 2001 From: Chris Donnay Date: Wed, 11 Oct 2023 16:04:38 -0400 Subject: [PATCH 3/4] fix lint error --- gerrychain/chain.py | 2 +- gerrychain/tree.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/gerrychain/chain.py b/gerrychain/chain.py index 880a90dc..8f1d730a 100644 --- a/gerrychain/chain.py +++ b/gerrychain/chain.py @@ -44,7 +44,7 @@ def __init__( is_valid = Validator([constraints]) else: is_valid = Validator(constraints) - + if not is_valid(initial_state): failed = [ constraint diff --git a/gerrychain/tree.py b/gerrychain/tree.py index fed5134f..40c3e85f 100644 --- a/gerrychain/tree.py +++ b/gerrychain/tree.py @@ -375,7 +375,6 @@ def recursive_tree_part( min_pop = max(pop_target * (1 - epsilon), pop_target * (1 - epsilon) - debt) max_pop = min(pop_target * (1 + epsilon), pop_target * (1 + epsilon) - debt) new_pop_target = (min_pop + max_pop) / 2 - nodes = method( graph.subgraph(remaining_nodes), pop_col=pop_col, From 6751a83965ef4d31cc294812a11204e8c8546d34 Mon Sep 17 00:00:00 2001 From: Peter Date: Wed, 11 Oct 2023 15:10:07 -0600 Subject: [PATCH 4/4] Removed white space that was messing up the linter --- gerrychain/chain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gerrychain/chain.py b/gerrychain/chain.py index 8f1d730a..4cf1c34b 100644 --- a/gerrychain/chain.py +++ b/gerrychain/chain.py @@ -44,7 +44,7 @@ def __init__( is_valid = Validator([constraints]) else: is_valid = Validator(constraints) - + if not is_valid(initial_state): failed = [ constraint