Skip to content

Commit 5c3b7d8

Browse files
authored
Merge branch 'main' into deploy-changehc
2 parents 7e99b5e + 0e089b7 commit 5c3b7d8

File tree

144 files changed

+131815
-4979
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+131815
-4979
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,7 @@ venv.bak/
126126
.retry
127127
.indicators-ansible-vault-pass
128128
indicators-ansible-vault-pass
129+
130+
# testing_utils
131+
testing_utils/cache
132+
testing_utils/*.csv

_delphi_utils_python/.pylintrc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
[DESIGN]
21

3-
min-public-methods=1
2+
[MESSAGES CONTROL]
43

4+
disable=logging-format-interpolation,
5+
too-many-locals,
6+
too-many-arguments,
7+
# Allow pytest functions to be part of a class.
8+
no-self-use,
9+
# Allow pytest classes to have one test.
10+
too-few-public-methods
511

6-
[MESSAGES CONTROL]
12+
[BASIC]
13+
14+
# Allow arbitrarily short-named variables.
15+
variable-rgx=[a-z_][a-z0-9_]*
16+
argument-rgx=[a-z_][a-z0-9_]*
17+
18+
[DESIGN]
719

8-
disable=R0801, C0330, E1101, E0611, C0114, C0116, C0103, R0913, R0914, W0702
20+
# Don't complain about pytest "unused" arguments.
21+
ignored-argument-names=(_.*|run_as_module)

_delphi_utils_python/data_proc/geomap/geo_data_proc.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ def create_jhu_uid_fips_crosswalk():
217217
{"jhu_uid": "63072999", "fips": "72000", "weight": 1.0},
218218
]
219219
)
220+
cruise_ships = pd.DataFrame(
221+
[
222+
{"jhu_uid": "84088888", "fips": "88888", "weight": 1.0},
223+
{"jhu_uid": "84099999", "fips": "99999", "weight": 1.0},
224+
]
225+
)
220226

221227
jhu_df = (
222228
pd.read_csv(JHU_FIPS_URL, dtype={"UID": str, "FIPS": str})
@@ -234,7 +240,7 @@ def create_jhu_uid_fips_crosswalk():
234240
# Drop the JHU UIDs that were hand-modified
235241
dup_ind = jhu_df["jhu_uid"].isin(
236242
pd.concat(
237-
[hand_additions, unassigned_states, out_of_state, puerto_rico_unassigned]
243+
[hand_additions, unassigned_states, out_of_state, puerto_rico_unassigned, cruise_ships]
238244
)["jhu_uid"].values
239245
)
240246
jhu_df.drop(jhu_df.index[dup_ind], inplace=True)
@@ -391,6 +397,7 @@ def create_fips_population_table():
391397
df_pr = df_pr.groupby("fips").sum().reset_index()
392398
df_pr = df_pr[~df_pr["fips"].isin(census_pop["fips"])]
393399
census_pop_pr = pd.concat([census_pop, df_pr])
400+
394401
census_pop_pr.to_csv(join(OUTPUT_DIR, FIPS_POPULATION_OUT_FILENAME), index=False)
395402

396403

_delphi_utils_python/delphi_utils/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
from .archive import ArchiveDiffer, GitArchiveDiffer, S3ArchiveDiffer
88
from .export import create_export_csv
99
from .utils import read_params
10+
1011
from .geomap import GeoMapper
12+
from .smooth import Smoother
1113
from .signal import add_prefix, public_signal
1214

1315
__version__ = "0.1.0"

_delphi_utils_python/delphi_utils/data/jhu_uid_fips_table.csv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ jhu_uid,fips,weight
8282
63072149,72149,1.0
8383
63072151,72151,1.0
8484
63072153,72153,1.0
85-
84088888,88888,1.0
86-
84099999,99999,1.0
8785
84000001,01000,1.0
8886
84000002,02000,1.0
8987
84000004,04000,1.0

_delphi_utils_python/delphi_utils/geomap.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,10 @@ def replace_geocode(
413413
df = df.groupby([new_col]).sum().reset_index()
414414
return df
415415

416-
def add_population_column(self, data, geocode_type, geocode_col=None):
416+
def add_population_column(self, data, geocode_type, geocode_col=None, dropna=True):
417417
"""
418-
Appends a population column to a dateframe, based on the FIPS or ZIP code.
418+
Appends a population column to a dataframe, based on the FIPS or ZIP code. If no
419+
dataframe is provided, the full crosswalk from geocode to population is returned.
419420
420421
Parameters
421422
---------
@@ -433,24 +434,26 @@ def add_population_column(self, data, geocode_type, geocode_col=None):
433434
A dataframe with a population column appended.
434435
"""
435436
geocode_col = geocode_type if geocode_col is None else geocode_col
437+
data = data.copy()
436438

437439
if geocode_type not in ["fips", "zip"]:
438440
raise ValueError(
439441
"Only fips and zip geocodes supported. \
440442
For other codes, aggregate those."
441443
)
442444

445+
pop_df = self._load_crosswalk(from_code=geocode_type, to_code="pop")
446+
443447
if not is_string_dtype(data[geocode_col]):
444448
data[geocode_col] = data[geocode_col].astype(str).str.zfill(5)
445449

446-
pop_df = self._load_crosswalk(from_code=geocode_type, to_code="pop")
447-
450+
merge_type = "inner" if dropna else "left"
448451
data_with_pop = (
449-
data.copy()
450-
.merge(pop_df, left_on=geocode_col, right_on=geocode_type, how="inner")
452+
data
453+
.merge(pop_df, left_on=geocode_col, right_on=geocode_type, how=merge_type)
451454
.rename(columns={"pop": "population"})
452455
)
453-
data_with_pop["population"] = data_with_pop["population"].astype(int)
456+
454457
return data_with_pop
455458

456459
@staticmethod

0 commit comments

Comments
 (0)