How to use the maup.assign.assign_by_covering 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_gives_same_answer_for_integer_indices(self, four_square_grid, squares_df):
        assignment = assign_by_area(squares_df, four_square_grid)
        expected = assign_by_covering(squares_df, four_square_grid)
        assert (expected == assignment).all()
github mggg / maup / tests / test_assign.py View on Github external
def test_assign_by_area_dispatches_to_non_integer_version(
        self, four_square_grid, squares_df
    ):
        targets = four_square_grid.set_index("ID")
        sources = squares_df.set_index("ID")
        assignment = assign_by_area(sources, targets)
        expected = assign_by_covering(sources, targets)
        assert (expected == assignment).all()
github mggg / maup / tests / test_assign.py View on Github external
def test_assign_can_be_used_with_groupby(four_square_grid, squares_df):
    assignment = assign_by_covering(squares_df, four_square_grid.set_index("ID"))

    result = squares_df.groupby(assignment)

    assert set(result.groups.keys()) == {"a", "b", "d"}
    assert set(result.indices["a"]) == {0, 1}
    assert set(result.indices["b"]) == {2}
    assert set(result.indices["d"]) == {3}
github mggg / maup / tests / test_assign.py View on Github external
def test_assign_gives_expected_answer_when_geoms_nest_neatly(
    four_square_grid, squares_within_four_square_grid
):
    result = set(
        assign_by_covering(
            squares_within_four_square_grid, four_square_grid.set_index("ID")
        ).items()
    )

    assert result == {(0, "a"), (1, "a"), (2, "b"), (3, "d")}
github mggg / maup / tests / test_assign.py View on Github external
def test_assign_assigns_geometries_when_they_nest_neatly(
    four_square_grid, squares_within_four_square_grid
):

    result = assign_by_covering(squares_within_four_square_grid, four_square_grid)
    assert len(list(result)) == len(squares_within_four_square_grid)
github mggg / maup / tests / test_assign.py View on Github external
def test_gives_same_answer_for_targets_with_non_integer_index(
        self, four_square_grid, squares_df
    ):
        targets = four_square_grid.set_index("ID")
        # targets = four_square_grid
        # sources = squares_df.set_index("ID")
        sources = squares_df
        assignment = assign_by_area(sources, targets)
        expected = assign_by_covering(sources, targets)
        assert (expected == assignment).all()
github mggg / maup / tests / test_assign.py View on Github external
def test_assigns_na_to_geometries_not_fitting_into_any_others(
    left_half_of_square_grid, squares_within_four_square_grid
):
    result = set(
        assign_by_covering(
            squares_within_four_square_grid, left_half_of_square_grid.set_index("ID")
        ).items()
    )

    assert result == {(0, "a"), (1, "a"), (2, "b"), (3, nan)}
github mggg / maup / tests / test_assign.py View on Github external
def test_assign_returns_iterable(four_square_grid, squares_within_four_square_grid):
    result = assign_by_covering(squares_within_four_square_grid, four_square_grid)
    assert iter(result)
github mggg / maup / tests / test_assign.py View on Github external
def test_gives_same_answer_when_both_have_non_integer_indices(
        self, four_square_grid, squares_df
    ):
        targets = four_square_grid.set_index("ID")
        sources = squares_df.set_index("ID")
        assignment = assign_by_area(sources, targets)
        expected = assign_by_covering(sources, targets)
        assert (expected == assignment).all()
github mggg / maup / tests / test_assign.py View on Github external
def test_assign_can_be_used_with_groupby_and_aggregate(four_square_grid, squares_df):
    assignment = assign_by_covering(squares_df, four_square_grid.set_index("ID"))

    result = squares_df.groupby(assignment)["data"].sum()

    expected = pandas.Series([2, 1, 1], index=["a", "b", "d"])
    assert (expected == result).all()