Ejemplo n.º 1
0
def test_joined_agg_hours_mismatch():
    """
    Test that join aggregate with mismatched hours doesn't warn.
    """
    mfl = MostFrequentLocation("2016-01-01 10:00", "2016-01-04", level="admin3")
    with warnings.catch_warnings(record=True) as w:
        mfl.join_aggregate(RadiusOfGyration("2016-01-01", "2016-01-04"))
        assert not w
Ejemplo n.º 2
0
def test_joined_agg_date_mismatch():
    """
    Test that join aggregate with mismatched dates raises a warning.
    """
    mfl = MostFrequentLocation("2016-01-01", "2016-01-04", level="admin3")
    with pytest.warns(UserWarning):
        mfl.join_aggregate(RadiusOfGyration("2016-01-02", "2016-01-04"))

    with pytest.warns(UserWarning):
        mfl.join_aggregate(RadiusOfGyration("2016-01-01", "2016-01-05"))
Ejemplo n.º 3
0
def test_joined_aggregate(get_dataframe):
    """
    Test join aggregate.
    """
    mfl = MostFrequentLocation("2016-01-01", "2016-01-04", level="admin3")
    joined = mfl.join_aggregate(RadiusOfGyration("2016-01-01", "2016-01-04"))
    assert (
        pytest.approx(203.12391560786)
        == get_dataframe(joined).set_index("pcod").loc["524 2 05 29"].rog
    )
Ejemplo n.º 4
0
def test_joined_aggregate(get_dataframe):
    """
    Test join aggregate.
    """
    mfl = MostFrequentLocation("2016-01-01", "2016-01-04", level="admin3")
    joined = mfl.join_aggregate(RadiusOfGyration("2016-01-01", "2016-01-04"))
    assert (
        pytest.approx(199.956021886114)
        == get_dataframe(joined).set_index("name").ix["Rasuwa"].rog
    )
Ejemplo n.º 5
0
def test_joined_median_aggregate(get_dataframe):
    """
    Test join with median aggregate.
    """
    mfl = MostFrequentLocation("2016-01-01", "2016-01-04", level="admin3")
    rog = RadiusOfGyration("2016-01-01", "2016-01-04")
    joined = mfl.join_aggregate(rog, method="median")
    rawus_avg = (
        get_dataframe(rog)
        .set_index("subscriber")
        .join(get_dataframe(mfl).set_index("subscriber"))
        .set_index("pcod")
        .loc["524 2 05 29"]
        .rog.median()
    )
    assert (
        pytest.approx(rawus_avg)
        == get_dataframe(joined).set_index("pcod").loc["524 2 05 29"].rog
    ), rawus_avg
Ejemplo n.º 6
0
def test_joined_modal_aggregate(get_dataframe):
    """
    Test join with modal aggregate.
    """
    mfl = MostFrequentLocation("2016-01-01", "2016-01-04", level="admin3")
    rog = SubscriberDegree("2016-01-01", "2016-01-04")
    joined = mfl.join_aggregate(rog, method="mode")
    rawus_mode = (
        get_dataframe(rog)
        .set_index("subscriber")
        .join(get_dataframe(mfl).set_index("subscriber"))
        .set_index("pcod")
        .loc["524 2 05 29"]
        .value.mode()[0]
    )
    assert (
        pytest.approx(rawus_mode)
        == get_dataframe(joined).set_index("pcod").loc["524 2 05 29"].value
    )