|
5 | 5 | import os |
6 | 6 |
|
7 | 7 | from delphi_hhs.run import _date_to_int, int_date_to_previous_day_datetime, generate_date_ranges, \ |
8 | | - make_signal, make_geo, run_module, pop_proportion |
| 8 | + make_signal, make_geo, run_module, transform_signal |
9 | 9 | from delphi_hhs.constants import SMOOTHERS, GEOS, SIGNALS, \ |
10 | 10 | CONFIRMED, SUM_CONF_SUSP, CONFIRMED_FLU, CONFIRMED_PROP, SUM_CONF_SUSP_PROP, CONFIRMED_FLU_PROP |
11 | 11 | from delphi_utils.geomap import GeoMapper |
@@ -89,40 +89,58 @@ def test_make_signal(): |
89 | 89 | with pytest.raises(Exception): |
90 | 90 | make_signal(data, "zig") |
91 | 91 |
|
92 | | -def test_pop_proportion(): |
| 92 | +def test_transform_signal_pop(): |
93 | 93 | geo_mapper = GeoMapper() |
94 | | - state_pop = geo_mapper.get_crosswalk("state_code", "pop") |
| 94 | + state_pop = geo_mapper.get_crosswalk("state_id", "pop") |
| 95 | + identity_smoother = SMOOTHERS[0] |
| 96 | + hundo_k = 100000 |
95 | 97 |
|
96 | 98 | test_df = pd.DataFrame({ |
97 | | - 'state': ['PA'], |
98 | | - 'state_code': [42], |
99 | | - 'timestamp': [datetime(year=2020, month=1, day=1)], |
100 | | - 'val': [15.],}) |
101 | | - |
102 | | - pa_pop = int(state_pop.loc[state_pop.state_code == "42", "pop"]) |
| 99 | + 'state': ['pa', 'wv'], |
| 100 | + 'timestamp': [datetime(year=2020, month=1, day=1)]*2, |
| 101 | + 'val': [15., 150.],}) |
| 102 | + |
| 103 | + pa_pop = int(state_pop.loc[state_pop.state_id == "pa", "pop"]) |
| 104 | + wv_pop = int(state_pop.loc[state_pop.state_id == "wv", "pop"]) |
| 105 | + assert True, \ |
| 106 | + transform_signal( |
| 107 | + CONFIRMED_PROP, |
| 108 | + identity_smoother, |
| 109 | + 'state', |
| 110 | + test_df.copy(), |
| 111 | + geo_mapper) |
103 | 112 | pd.testing.assert_frame_equal( |
104 | | - pop_proportion(test_df, geo_mapper), |
| 113 | + transform_signal( |
| 114 | + CONFIRMED_PROP, |
| 115 | + identity_smoother, |
| 116 | + 'state', |
| 117 | + test_df.copy(), |
| 118 | + geo_mapper), |
105 | 119 | pd.DataFrame({ |
106 | | - 'state': ['PA'], |
107 | | - 'state_code': [42], |
108 | | - 'timestamp': [datetime(year=2020, month=1, day=1)], |
109 | | - 'val': [15/pa_pop*100000],}) |
| 120 | + 'geo_id': ['pa', 'wv'], |
| 121 | + 'timestamp': [datetime(year=2020, month=1, day=1)]*2, |
| 122 | + 'val': [15/pa_pop*hundo_k, 150/wv_pop*hundo_k], |
| 123 | + 'se': [None]*2, |
| 124 | + 'sample_size': [None]*2,}), |
| 125 | + check_dtype=False, |
| 126 | + check_like=True |
110 | 127 | ) |
111 | 128 |
|
112 | | - test_df= pd.DataFrame({ |
113 | | - 'state': ['WV'], |
114 | | - 'state_code': [54], |
115 | | - 'timestamp': [datetime(year=2020, month=1, day=1)], |
116 | | - 'val': [150.],}) |
117 | | - |
118 | | - wv_pop = int(state_pop.loc[state_pop.state_code == "54", "pop"]) |
119 | 129 | pd.testing.assert_frame_equal( |
120 | | - pop_proportion(test_df, geo_mapper), |
| 130 | + transform_signal( |
| 131 | + CONFIRMED_PROP, |
| 132 | + identity_smoother, |
| 133 | + 'nation', |
| 134 | + test_df.copy(), |
| 135 | + geo_mapper), |
121 | 136 | pd.DataFrame({ |
122 | | - 'state': ['WV'], |
123 | | - 'state_code': [54], |
| 137 | + 'geo_id': ['us'], |
124 | 138 | 'timestamp': [datetime(year=2020, month=1, day=1)], |
125 | | - 'val': [150/wv_pop*100000],}) |
| 139 | + 'val': [165/(pa_pop+wv_pop)*hundo_k], |
| 140 | + 'se': [None], |
| 141 | + 'sample_size': [None],}), |
| 142 | + check_dtype=False, |
| 143 | + check_like=True |
126 | 144 | ) |
127 | 145 |
|
128 | 146 | def test_make_geo(): |
|
0 commit comments