-
Notifications
You must be signed in to change notification settings - Fork 23
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
Example in README loses votes and contains non-explicit assumptions #34
Labels
bug
Something isn't working
Comments
Note: forcing the source and target geometries to be cropped to each other like so does not resolve the issue. precincts["geometry"] = maup.crop_to(precincts, blocks)
blocks["geometry"] = maup.crop_to(blocks, precincts) Additionally, cropping then dropping the cropped out blocks also does not resolve the issue: blocks = blocks.drop(blocks[blocks.area==0].index) |
This works. You need to BOTH drop the empty geometries and weight with respect to assignment. import geopandas as gpd
import geopandas
import maup
import math
blocks = geopandas.read_file("zip://./examples/blocks.zip")
precincts = geopandas.read_file("zip://./examples/precincts.zip")
districts = geopandas.read_file("zip://./examples/districts.zip")
precincts["geometry"] = maup.crop_to(precincts, blocks)
blocks["geometry"] = maup.crop_to(blocks, precincts)
blocks = blocks[~blocks["geometry"].is_empty]
election_columns = ["PRES16D", "PRES16R"]
assignment = maup.assign(blocks, precincts)
blocks['assignment'] = assignment
weights = blocks.TOTPOP / assignment.map(blocks.TOTPOP.groupby(assignment).sum())
assert math.isclose(sum(weights),len(precincts))
prorated = maup.prorate(assignment, precincts[election_columns], weights)
blocks[election_columns] = prorated
print(blocks[election_columns].sum())
print(precincts[election_columns].sum())
|
pjrule
added a commit
that referenced
this issue
Feb 8, 2023
* Make the weights in the README have explicit assumptions Fixes #34, finally . . . --------- Co-authored-by: Parker J. Rule <parker.rule@tufts.edu>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
forcing precinct TOTPOP to equal block TOTPOP doesn't resovle the issue:
The text was updated successfully, but these errors were encountered: