Skip to content

Commit 291e316

Browse files
committed
refactor(geomap): clean up code
* format with black * simplify imports * refactor a few tests
1 parent 3fc3254 commit 291e316

File tree

6 files changed

+154
-135
lines changed

6 files changed

+154
-135
lines changed

_delphi_utils_python/data_proc/geomap/geo_data_proc.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from os import remove, listdir
1313
from os.path import join, isfile
1414
from zipfile import ZipFile
15-
from pandas.core.frame import DataFrame
1615

1716
import requests
1817
import pandas as pd
@@ -70,8 +69,8 @@ def create_fips_zip_crosswalk():
7069
# Find the population fractions (the heaviest computation, takes about a minute)
7170
# Note that the denominator in the fractions is the source population
7271
pop_df.set_index(["fips", "zip"], inplace=True)
73-
fips_zip: DataFrame = pop_df.groupby("fips", as_index=False).apply(lambda g: g["pop"] / g["pop"].sum())
74-
zip_fips: DataFrame = pop_df.groupby("zip", as_index=False).apply(lambda g: g["pop"] / g["pop"].sum())
72+
fips_zip: pd.DataFrame = pop_df.groupby("fips", as_index=False).apply(lambda g: g["pop"] / g["pop"].sum())
73+
zip_fips: pd.DataFrame = pop_df.groupby("zip", as_index=False).apply(lambda g: g["pop"] / g["pop"].sum())
7574

7675
# Rename and write to file
7776
fips_zip = fips_zip.reset_index(level=["fips", "zip"]).rename(columns={"pop": "weight"}).query("weight > 0.0")
@@ -228,7 +227,7 @@ def create_state_population_table():
228227
derive_fips_state_crosswalk()
229228

230229
census_pop = pd.read_csv(join(OUTPUT_DIR, FIPS_POPULATION_OUT_FILENAME), dtype={"fips": str, "pop": int})
231-
state: DataFrame = pd.read_csv(join(OUTPUT_DIR, FIPS_STATE_OUT_FILENAME), dtype=str)
230+
state: pd.DataFrame = pd.read_csv(join(OUTPUT_DIR, FIPS_STATE_OUT_FILENAME), dtype=str)
232231
state_pop = state.merge(census_pop, on="fips").groupby(["state_code", "state_id", "state_name"], as_index=False).sum()
233232
state_pop.sort_values("state_code").to_csv(join(OUTPUT_DIR, STATE_POPULATION_OUT_FILENAME), index=False)
234233

0 commit comments

Comments
 (0)