Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport various funcs to maintain backwards compatibility with Python 3.8, etc. #54

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 4 additions & 4 deletions evaltools/scoring/partisan.py
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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
return float(np.mean(list(result.values()))) if mean else result
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down