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
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 )
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 )
def test_most_frequent_locations_column_names(get_dataframe, exemplar_level_param): """ MostFrequentLocations().get_dataframe() returns a dataframe. """ mfl = MostFrequentLocation("2016-01-01", "2016-01-02", **exemplar_level_param) df = get_dataframe(mfl) assert df.columns.tolist() == mfl.column_names
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
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 )
def test_equivalent_to_locate_subscribers(get_dataframe): """ daily_location() is equivalent to the MostFrequentLocation(). """ mfl = MostFrequentLocation("2016-01-01", "2016-01-02") mfl_df = get_dataframe(mfl) dl = daily_location("2016-01-01", method="most-common") dl_df = get_dataframe(dl) assert (dl_df == mfl_df).all().all()
def test_lat_lons(get_dataframe): """ MostFrequentLocations() has the correct values at the lat-lon level. """ mfl = MostFrequentLocation("2016-01-01", "2016-01-02", level="lat-lon") df = get_dataframe(mfl) df.set_index("subscriber", inplace=True) assert pytest.approx(28.941925079951545) == float(df.ix["1QBlwRo4Kd5v3Ogz"].lat) assert pytest.approx(82.61895799084449) == float(df.ix["1QBlwRo4Kd5v3Ogz"].lon)
def test_vsites(get_dataframe): """ MostFrequentLocation() returns the correct locations. """ mfl = MostFrequentLocation("2016-01-01", "2016-01-02", level="versioned-site") df = get_dataframe(mfl) df.set_index("subscriber", inplace=True) assert "wzrXjw" == df.ix["yqQ6m96rp09dn510"].site_id assert "qvkp6J" == df.ix["zvaOknzKbEVD2eME"].site_id
def test_equivalent_to_locate_subscribers_with_time(get_dataframe): """ daily_location() is equivalent to the MostFrequentLocation() with timestamps. """ mfl = MostFrequentLocation("2016-01-01 18:00:00", "2016-01-02 06:00:00") mfl_df = get_dataframe(mfl) dl = daily_location("2016-01-01 18:00:00", stop="2016-01-02 06:00:00", method="most-common") dl_df = get_dataframe(dl) assert (dl_df == mfl_df).all().all()
def test_lon_lats(get_dataframe): """ MostFrequentLocations() has the correct values at the lon-lat spatial unit. """ mfl = MostFrequentLocation( "2016-01-01", "2016-01-02", spatial_unit=make_spatial_unit("lon-lat") ) df = get_dataframe(mfl) df.set_index("subscriber", inplace=True) assert pytest.approx(82.61895799084449) == float(df.loc["1QBlwRo4Kd5v3Ogz"].lon) assert pytest.approx(28.941925079951545) == float(df.loc["1QBlwRo4Kd5v3Ogz"].lat)
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"))