예제 #1
0
def test_last_location_column_names(exemplar_level_param, get_dataframe):
    """
    LastLocation() is able to return a dataframe.
    """

    last_loc = LastLocation("2016-01-01", "2016-01-02", **exemplar_level_param)
    df = get_dataframe(last_loc)
    assert df.columns.tolist() == last_loc.column_names
예제 #2
0
def test_last_loc_vsite(get_dataframe):
    """
    LastLocation() returns correct last location.
    """

    last_loc = LastLocation("2016-01-01", "2016-01-02", level="versioned-site")

    df = get_dataframe(last_loc)
    df.set_index("subscriber", inplace=True)
    assert "QeBRM8" == df.loc["038OVABN11Ak4W5P"].site_id
    assert "dJb0Wd" == df.loc["zGWn8opVmOQAD6xY"].site_id
예제 #3
0
def test_last_loc_lat_lon(get_dataframe):
    """
    LastLocation() can make queries at the lat-lon level.
    """

    last_loc = LastLocation("2016-01-01", "2016-01-02", level="lat-lon")
    df = get_dataframe(last_loc)
    df.set_index("subscriber", inplace=True)
    assert pytest.approx(29.135638957790576) == float(
        df.loc["yqw50eNyEwOxNDGL"].lat)
    assert pytest.approx(83.09669810947962) == float(
        df.loc["yqw50eNyEwOxNDGL"].lon)
예제 #4
0
def test_unmoving_at_reference_location_column_names(
        get_column_names_from_run):
    assert get_column_names_from_run(
        UnmovingAtReferenceLocation(
            locations=UniqueLocations(
                SubscriberLocations(
                    "2016-01-01",
                    "2016-01-01 10:00",
                    spatial_unit=make_spatial_unit("admin", level=3),
                )),
            reference_locations=LastLocation("2016-01-01", "2016-01-02"),
        )) == ["subscriber", "value"]
예제 #5
0
def test_unmoving_at_reference_location_values(get_dataframe):
    df = get_dataframe(
        UnmovingAtReferenceLocation(
            locations=UniqueLocations(
                SubscriberLocations(
                    "2016-01-01",
                    "2016-01-01 10:00",
                    spatial_unit=make_spatial_unit("admin", level=3),
                )),
            reference_locations=LastLocation("2016-01-01", "2016-01-02"),
        )).set_index("subscriber")
    assert not df.loc["038OVABN11Ak4W5P"].value
    assert df.loc["3XKdxqvyNxO2vLD1"].value
예제 #6
0
def test_spatial_unit_mismatch_error():
    with pytest.raises(ValueError, match="Spatial unit mismatch"):
        UnmovingAtReferenceLocation(
            locations=UniqueLocations(
                SubscriberLocations(
                    "2016-01-01",
                    "2016-01-01 10:00",
                    spatial_unit=make_spatial_unit("admin", level=2),
                )),
            reference_locations=LastLocation(
                "2016-01-01",
                "2016-01-02",
                spatial_unit=make_spatial_unit("admin", level=3),
            ),
        )
예제 #7
0
def test_unmoving_at_reference_location_counts_values(get_dataframe):
    df = get_dataframe(
        UnmovingAtReferenceLocationCounts(
            UnmovingAtReferenceLocation(
                locations=UniqueLocations(
                    SubscriberLocations(
                        "2016-01-01",
                        "2016-01-01 10:00",
                        spatial_unit=make_spatial_unit("admin", level=1),
                    )),
                reference_locations=LastLocation(
                    "2016-01-01",
                    "2016-01-02",
                    spatial_unit=make_spatial_unit("admin", level=1),
                ),
            ))).set_index("pcod")
    assert df.loc["524 1"].value == 2
    assert df.loc["524 4"].value == 26
def test_unmoving_at_reference_location_counts_column_names(
        get_column_names_from_run):
    assert (get_column_names_from_run(
        RedactedUnmovingAtReferenceLocationCounts(
            unmoving_at_reference_location_counts=
            UnmovingAtReferenceLocationCounts(
                UnmovingAtReferenceLocation(
                    locations=UniqueLocations(
                        SubscriberLocations(
                            "2016-01-01",
                            "2016-01-01 10:00",
                            spatial_unit=make_spatial_unit("admin", level=1),
                        )),
                    reference_locations=LastLocation(
                        "2016-01-01",
                        "2016-01-02",
                        spatial_unit=make_spatial_unit("admin", level=1),
                    ),
                )))) == ["pcod", "value"])