def test_column_names_unique_location_counts(exemplar_level_param):
    """ Test that column_names property matches head(0) for UniqueLocationCounts"""
    lv = UniqueLocationCounts("2016-01-01",
                              "2016-01-02",
                              **exemplar_level_param,
                              hours=(5, 17))
    assert lv.head(0).columns.tolist() == lv.column_names
def test_correct_counts(get_dataframe):
    """
    UniqueLocationCounts returns correct counts.
    """
    ulc = UniqueLocationCounts("2016-01-01",
                               "2016-01-02",
                               level="cell",
                               hours=(5, 17))
    df = get_dataframe(ulc)
    dful = get_dataframe(
        subscriber_locations("2016-01-01",
                             "2016-01-02",
                             level="cell",
                             hours=(5, 17)))
    assert [
        df["unique_location_counts"][0],
        df["unique_location_counts"][1],
        df["unique_location_counts"][2],
    ] == [
        len(dful[dful["subscriber"] == df["subscriber"][0]]
            ["location_id"].unique()),
        len(dful[dful["subscriber"] == df["subscriber"][1]]
            ["location_id"].unique()),
        len(dful[dful["subscriber"] == df["subscriber"][2]]
            ["location_id"].unique()),
    ]
Exemplo n.º 3
0
def test_correct_counts(get_dataframe):
    """
    UniqueLocationCounts returns correct counts.
    """
    ulc = UniqueLocationCounts(
        "2016-01-01",
        "2016-01-02",
        spatial_unit=make_spatial_unit("cell"),
        hours=(5, 17),
    )
    df = get_dataframe(ulc)
    dful = get_dataframe(
        SubscriberLocations(
            "2016-01-01",
            "2016-01-02",
            spatial_unit=make_spatial_unit("cell"),
            hours=(5, 17),
        ))
    assert [df["value"][0], df["value"][1], df["value"][2]] == [
        len(dful[dful["subscriber"] == df["subscriber"][0]]
            ["location_id"].unique()),
        len(dful[dful["subscriber"] == df["subscriber"][1]]
            ["location_id"].unique()),
        len(dful[dful["subscriber"] == df["subscriber"][2]]
            ["location_id"].unique()),
    ]
Exemplo n.º 4
0
    def _unsampled_query_obj(self):
        """
        Return the underlying flowmachine unique_location_counts object.

        Returns
        -------
        Query
        """
        return UniqueLocationCounts(
            start=self.start_date,
            stop=self.end_date,
            spatial_unit=get_spatial_unit_obj(self.aggregation_unit),
            subscriber_subset=self.subscriber_subset,
        )
Exemplo n.º 5
0
    def _flowmachine_query_obj(self):
        """
        Return the underlying flowmachine unique_location_counts object.

        Returns
        -------
        Query
        """
        return UniqueLocationCounts(
            start=self.start_date,
            stop=self.end_date,
            spatial_unit=self.aggregation_unit,
            tables=self.event_types,
            subscriber_subset=self.subscriber_subset,
        )
def test_returns_errors():
    """
    Test level exists
    """
    with pytest.raises(BadLevelError):
        UniqueLocationCounts("2016-01-01", "2016-01-02", level="foo")
Exemplo n.º 7
0
def test_returns_errors():
    """
    Test spatial unit exists
    """
    with pytest.raises(InvalidSpatialUnitError):
        UniqueLocationCounts("2016-01-01", "2016-01-02", spatial_unit="foo")