How to use the maup.assign function in maup

To help you get started, we’ve selected a few maup examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mggg / maup / tests / test_assign.py View on Github external
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()
github mggg / maup / tests / test_prorate.py View on Github external
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