From e7a01221eba525ce7c97d1f22295349363da7600 Mon Sep 17 00:00:00 2001 From: Max Fan Date: Mon, 16 May 2022 08:42:35 -0400 Subject: [PATCH 1/3] Backport functools.cache call to use lru_cache for max backwards compat --- evaltools/scoring/partisan.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/evaltools/scoring/partisan.py b/evaltools/scoring/partisan.py index 277cd414..e8184663 100644 --- a/evaltools/scoring/partisan.py +++ b/evaltools/scoring/partisan.py @@ -1,16 +1,16 @@ -from functools import cache +from functools import lru_cache from gerrychain import Partition import numpy as np from typing import Iterable, Tuple from .score_types import * -@cache +@lru_cache(maxsize=None) def _election_results(part: Partition, election_cols: Tuple[str], party: str): return np.array([ np.array([part[e].percent(party, d) for d in sorted(part.parts.keys()) if d != -1]) for e in election_cols ]) -@cache +@lru_cache(maxsize=None) def _election_stability(part: Partition, election_cols: Tuple[str], party: str): return (_election_results(part, election_cols, party) > 0.5).sum(axis=0) @@ -88,4 +88,4 @@ def _eguia_election(part: Partition, e: str, party: str, county_part: Partition, def _eguia(part: Partition, election_cols: Iterable[str], party: str, county_part: Partition, totpop_col: str, mean: bool = False) -> ScoreValue: result = {e: _eguia_election(part, e, party, county_part, totpop_col) for e in election_cols} - return float(np.mean(list(result.values()))) if mean else result \ No newline at end of file + return float(np.mean(list(result.values()))) if mean else result From 28f9b021e244ca902ad38b2a3657bca50bb7451d Mon Sep 17 00:00:00 2001 From: Max Fan Date: Mon, 16 May 2022 08:49:04 -0400 Subject: [PATCH 2/3] Add maup as an explicit dep --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 8b825671..1fad5bd2 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ requirements = [ "pandas", "scipy", "networkx", "geopandas", "shapely", "matplotlib", "gerrychain", "sortedcontainers", "gurobipy", "jsonlines", "opencv-python", - "imageio", "us", "pydantic", "censusdata", "seaborn" + "imageio", "us", "pydantic", "censusdata", "seaborn", "maup" ] setup( From 90973bc166fe0029ea651f120f2f5204d24679f1 Mon Sep 17 00:00:00 2001 From: Max Fan Date: Mon, 16 May 2022 09:16:12 -0400 Subject: [PATCH 3/3] Fix broken docs link in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2f8aaef9..2bf01135 100644 --- a/README.md +++ b/README.md @@ -222,7 +222,7 @@ chunks = { indicates that the districting plan creates 16 pieces of county. ## Documentation -Read the documentation [here](https://mggg.github.io/plan-evaluation-tools/). To +Read the documentation [here](https://mggg.github.io/evaltools/). To create documentation after adding features, please ensure you're following the [Google Python style guide](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings), then run `sh docs.sh`. Pushing to the repository will modify the documentation automatically.