Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_assign_dispatches_to_without_area_and_with_area(
four_square_grid, squares_some_neat_some_overlapping, crs
):
other = four_square_grid.set_index("ID")
other.crs = crs
print(squares_some_neat_some_overlapping.crs, other.crs)
assignment = assign(squares_some_neat_some_overlapping, other)
expected = pandas.Series(
["a", "a", "b", "d", "b"], index=squares_some_neat_some_overlapping.index
)
assert (expected == assignment).all()
def test_example_case():
blocks = geopandas.read_file("zip://./examples/blocks.zip")
old_precincts = geopandas.read_file("zip://./examples/precincts.zip")
new_precincts = geopandas.read_file("zip://./examples/new_precincts.zip")
columns = ["SEN18D", "SEN18R"]
# Include area_cutoff=0 to ignore any intersections with no area,
# like boundary intersections, which we do not want to include in
# our proration.
pieces = intersections(old_precincts, new_precincts, area_cutoff=0)
# Weight by prorated population from blocks
weights = blocks["TOTPOP"].groupby(assign(blocks, pieces)).sum()
# Use blocks to estimate population of each piece
new_precincts[columns] = prorate(pieces, old_precincts[columns], weights=weights)
assert (new_precincts[columns] > 0).sum().sum() > len(new_precincts) / 2