def test_joined_modal_aggregate(self): """ 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 = (rog.get_dataframe().set_index("subscriber").join( mfl.get_dataframe().set_index("subscriber")).set_index( "name").ix["Rasuwa"].degree.mode()[0]) self.assertAlmostEqual( joined.get_dataframe().set_index("name").ix["Rasuwa"].degree, rawus_mode)
def _unsampled_query_obj(self): """ Return the underlying flowmachine subscriber_degree object. Returns ------- Query """ return SubscriberDegree( start=self.start, stop=self.stop, direction=self.direction, subscriber_subset=self.subscriber_subset, )
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_collects_metrics(): """ Test that we can instantiate flowmachine.feature_collection with list of objects. """ start, stop = "2016-01-01", "2016-01-03" metrics = [ RadiusOfGyration(start, stop), NocturnalEvents(start, stop), SubscriberDegree(start, stop), ] expected_columns = [ "subscriber", "value_radiusofgyration_0", "value_nocturnalevents_1", "value_subscriberdegree_2", ] fc = feature_collection(metrics) column_names = fc.column_names assert expected_columns == column_names