Skip to content

Commit 6a7fd65

Browse files
authored
Merge pull request #533 from cmu-delphi/fix_usafacts_prop
USAFacts Prop Fix
2 parents 519001f + e0544d9 commit 6a7fd65

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

usafacts/delphi_usafacts/geo.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ def geo_map(df: pd.DataFrame, geo_res: str, map_df: pd.DataFrame, sensor: str):
107107
df = df.append(unassigned_counties)
108108
geo_mapper = GeoMapper()
109109
df = geo_mapper.add_geocode(df, "fips", "state_id", new_col="geo_id")
110+
111+
# Zero out the state FIPS population to avoid double counting.
112+
df = df.set_index("fips")
113+
state_fips_codes = {str(x).zfill(2) + "000" for x in range(1, 73)}
114+
subset_state_fips_codes = set(df.index.values) & state_fips_codes
115+
df.loc[subset_state_fips_codes, "population"] = 0
116+
df = df.reset_index()
110117
elif geo_res in ("msa", "hrr"):
111118
# Map "missing" secondary FIPS to those that are in our canonical set
112119
for fips, fips_list in SECONDARY_FIPS:

usafacts/tests/test_geo.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ def test_state(self):
7676
"""Tests that values are correctly aggregated at the state level."""
7777
df = pd.DataFrame(
7878
{
79-
"fips": ["04001", "04003", "04009", "25023"],
80-
"timestamp": ["2020-02-15", "2020-02-15", "2020-02-15", "2020-02-15"],
81-
"new_counts": [10, 15, 2, 13],
82-
"cumulative_counts": [100, 20, 45, 60],
83-
"population": [100, 2100, 300, 25],
79+
"fips": ["04001", "04003", "04009", "25023", "25000"],
80+
"timestamp": ["2020-02-15", "2020-02-15", "2020-02-15", "2020-02-15", "2020-02-15"],
81+
"new_counts": [10, 15, 2, 13, 0],
82+
"cumulative_counts": [100, 20, 45, 60, 0],
83+
"population": [100, 2100, 300, 25, 25],
8484
}
8585
)
8686

0 commit comments

Comments
 (0)