Exemplo n.º 1
0
    def test_incorrect_geo(self):
        """Tests that an invalid resolution raises an error."""
        df = pd.DataFrame({
            "fips": ["53003", "48027", "50103"],
            "timestamp": ["2020-02-15", "2020-02-15", "2020-02-15"],
            "new_counts": [10, 15, 2],
            "cumulative_counts": [100, 20, 45],
        })

        with pytest.raises(ValueError):
            geo_map(df, "département", SENSOR)
Exemplo n.º 2
0
    def test_state_hhs_nation(self):
        """Tests that values are correctly aggregated at the state, HHS, and nation level."""
        df = pd.DataFrame({
            "fips": ["04001", "04003", "04009", "25023", "25000"],
            "timestamp": [
                "2020-02-15", "2020-02-15", "2020-02-15", "2020-02-15",
                "2020-02-15"
            ],
            "new_counts": [10, 15, 2, 13, 1],
            "cumulative_counts": [100, 20, 45, 60, 1],
        })

        state_df = geo_map(df, "state", SENSOR)
        pd.testing.assert_frame_equal(
            state_df,
            pd.DataFrame({
                "geo_id": ["az", "ma"],
                "timestamp": ["2020-02-15"] * 2,
                "new_counts": [27, 14],
                "cumulative_counts": [165, 61],
                "population": [236646., 521202.],
                "incidence": [27 / 236646 * 100000, 14 / 521202 * 100000],
                "cumulative_prop":
                [165 / 236646 * 100000, 61 / 521202 * 100000]
            }))

        hhs_df = geo_map(df, "hhs", SENSOR)
        pd.testing.assert_frame_equal(
            hhs_df,
            pd.DataFrame({
                "geo_id": ["1", "9"],
                "timestamp": ["2020-02-15"] * 2,
                "new_counts": [14, 27],
                "cumulative_counts": [61, 165],
                "population": [521202., 236646.],
                "incidence": [14 / 521202 * 100000, 27 / 236646 * 100000],
                "cumulative_prop":
                [61 / 521202 * 100000, 165 / 236646 * 100000]
            }))

        nation_df = geo_map(df, "nation", SENSOR)
        pd.testing.assert_frame_equal(
            nation_df,
            pd.DataFrame({
                "geo_id": ["us"],
                "timestamp": ["2020-02-15"],
                "new_counts": [41],
                "cumulative_counts": [226],
                "population": [521202.0 + 236646],
                "incidence": [41 / (521202 + 236646) * 100000],
                "cumulative_prop": [226 / (521202 + 236646) * 100000]
            }))
Exemplo n.º 3
0
 def test_hrr_msa(self):
     """Tests that values are correctly aggregated at the HRR and MSA level."""
     df = pd.DataFrame({
         "fips": ["13009", "13017", "13021", "09015"],
         "timestamp":
         ["2020-02-15", "2020-02-15", "2020-02-15", "2020-02-15"],
         "new_counts": [10, 15, 2, 13],
         "cumulative_counts": [100, 20, 45, 60],
     })
     hrr_df = geo_map(df, "hrr", SENSOR)
     msa_df = geo_map(df, "msa", SENSOR)
     assert msa_df.shape == (2, 7)
     gmpr = GeoMapper()
     df = gmpr.add_population_column(df, "fips")
     assert np.isclose(hrr_df.new_counts.sum(), df.new_counts.sum())
     assert np.isclose(hrr_df.population.sum(), df.population.sum())
     assert hrr_df.shape == (5, 7)
Exemplo n.º 4
0
    def test_county(self):
        """Tests that values are correctly aggregated at the county level."""
        df = pd.DataFrame({
            "fips": ["53003", "48027", "50103"],
            "timestamp": ["2020-02-15", "2020-02-15", "2020-02-15"],
            "new_counts": [10, 15, 2],
            "cumulative_counts": [100, 20, 45],
        })
        new_df = geo_map(df, "county", SENSOR)
        gmpr = GeoMapper()
        df = gmpr.add_population_column(df, "fips")
        exp_incidence = df["new_counts"] / df["population"] * 100000
        exp_cprop = df["cumulative_counts"] / df["population"] * 100000

        assert set(new_df["geo_id"].values) == set(df["fips"].values)
        assert set(new_df["timestamp"].values) == set(df["timestamp"].values)
        assert set(new_df["incidence"].values) == set(exp_incidence.values)
        assert set(new_df["cumulative_prop"].values) == set(exp_cprop.values)
 def test_hrr(self):
     """Tests that values are correctly aggregated at the HRR level."""
     df = pd.DataFrame(
         {
             "fips": ["13009", "13017", "13021", "09015"],
             "timestamp": ["2020-02-15", "2020-02-15", "2020-02-15", "2020-02-15"],
             "new_counts": [10, 15, 2, 13],
             "cumulative_counts": [100, 20, 45, 60],
             "population": [100, 2100, 300, 25],
         }
     )
     new_df = geo_map(df, "hrr", SENSOR)
     pd.testing.assert_frame_equal(
         new_df.round(5),
         pd.DataFrame({
             "geo_id": ["110", "123", "140", "145", "147"],
             "timestamp": ["2020-02-15"]*5,
             "new_counts": [13.0, 0.11143, 0.09867, 0.00809, 26.78180],
             "cumulative_counts": [60.0, 0.14858, 0.13156, 0.08093, 164.63893],
             "population": [25.0, 15.60054, 13.81422, 0.08093, 2470.50431],
             "incidence": [52000.0, 714.28571, 714.28571, 10000.0, 1084.06214],
             "cumulative_prop": [240000.0, 952.38095, 952.38095, 100000.0, 6664.18316]
         })
     )
    def test_state(self):
        """Tests that values are correctly aggregated at the state level."""
        df = pd.DataFrame(
            {
                "fips": ["04001", "04003", "04009", "25023", "25000"],
                "timestamp": ["2020-02-15", "2020-02-15", "2020-02-15", "2020-02-15", "2020-02-15"],
                "new_counts": [10, 15, 2, 13, 0],
                "cumulative_counts": [100, 20, 45, 60, 0],
                "population": [100, 2100, 300, 25, 25],
            }
        )

        new_df = geo_map(df, "state", SENSOR)

        exp_incidence = np.array([27, 13]) / np.array([2500, 25]) * 100000
        exp_cprop = np.array([165, 60]) / np.array([2500, 25]) * 100000

        assert (new_df["geo_id"].values == ["az", "ma"]).all()
        assert (new_df["timestamp"].values == ["2020-02-15", "2020-02-15"]).all()
        assert (new_df["new_counts"].values == [27, 13]).all()
        assert (new_df["cumulative_counts"].values == [165, 60]).all()
        assert (new_df["population"].values == [2500, 25]).all()
        assert (new_df["incidence"].values == exp_incidence).all()
        assert (new_df["cumulative_prop"].values == exp_cprop).all()
 def test_msa(self):
     """Tests that values are correctly aggregated at the MSA level."""
     df = pd.DataFrame(
         {
             "fips": ["13009", "13017", "13021", "09015"],
             "timestamp": ["2020-02-15", "2020-02-15", "2020-02-15", "2020-02-15"],
             "new_counts": [10, 15, 2, 13],
             "cumulative_counts": [100, 20, 45, 60],
             "population": [100, 2100, 300, 25],
         }
     )
     new_df = geo_map(df, "msa", SENSOR)
     pd.testing.assert_frame_equal(
         new_df.round(5),
         pd.DataFrame({
             "geo_id": ["31420", "49340"],
             "timestamp": ["2020-02-15"]*2,
             "new_counts": [2.0, 13.0],
             "cumulative_counts": [45.0, 60.0],
             "population": [300, 25],
             "incidence": [666.66667, 52000.0],
             "cumulative_prop": [15000.0, 240000.0]
         })
     )