Skip to content

Commit 1a1bba7

Browse files
committed
change code name
1 parent f74aefd commit 1a1bba7

File tree

7 files changed

+61
-61
lines changed

7 files changed

+61
-61
lines changed

_delphi_utils_python/data_proc/geomap/geo_data_proc.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141
FIPS_HRR_OUT_FILENAME = "fips_hrr_table.csv"
4242
FIPS_ZIP_OUT_FILENAME = "fips_zip_table.csv"
4343
FIPS_HHS_FILENAME = "fips_hhs_table.csv"
44-
FIPS_POPSAFEFIPS_OUT_FILENAME = "fips_popsafe-fips_table.csv"
44+
FIPS_CHNGFIPS_OUT_FILENAME = "fips_chng-fips_table.csv"
4545
FIPS_POPULATION_OUT_FILENAME = "fips_pop.csv"
4646

47-
POPSAFEFIPS_STATE_OUT_FILENAME = "popsafe-fips_state_table.csv"
47+
CHNGFIPS_STATE_OUT_FILENAME = "chng-fips_state_table.csv"
4848
ZIP_HSA_OUT_FILENAME = "zip_hsa_table.csv"
4949
ZIP_HRR_OUT_FILENAME = "zip_hrr_table.csv"
5050
ZIP_FIPS_OUT_FILENAME = "zip_fips_table.csv"
@@ -478,8 +478,8 @@ def derive_zip_hhs_crosswalk():
478478
zip_state.sort_values(["zip", "hhs"]).to_csv(join(OUTPUT_DIR, ZIP_HHS_FILENAME), index=False)
479479

480480

481-
def derive_fips_popsafefips_crosswalk():
482-
"""Build a crosswalk table for FIPS to pop-safe fips."""
481+
def derive_fips_chngfips_crosswalk():
482+
"""Build a crosswalk table for FIPS to CHNG FIPS."""
483483
if not isfile(join(OUTPUT_DIR, FIPS_STATE_OUT_FILENAME)):
484484
derive_fips_state_crosswalk()
485485

@@ -506,35 +506,35 @@ def derive_fips_popsafefips_crosswalk():
506506
county_groups["group"] = county_groups["group"].str.zfill(2).astype("string")
507507
county_groups["fips"] = county_groups["fips"].str.zfill(5).astype("string")
508508
# Combine state codes and group ids into a single FIPS code.
509-
county_groups["popsafe-fips"] = county_groups["state_fips"] + "g" + county_groups["group"]
509+
county_groups["chng-fips"] = county_groups["state_fips"] + "g" + county_groups["group"]
510510

511-
county_groups = county_groups[["fips", "popsafe-fips"]]
511+
county_groups = county_groups[["fips", "chng-fips"]]
512512
fips_to_state = pd.read_csv(join(OUTPUT_DIR, FIPS_STATE_OUT_FILENAME), dtype="string", index_col=False)
513513

514514
# Get all the fips that aren't included in the low-population groupings.
515515
extra_fips_list = list(set(fips_to_state.fips) - set(county_groups.fips))
516-
# Normal fips codes and pop-safe fips codes are the same for high-population counties.
517-
extra_fips_df = pd.DataFrame({"fips" : extra_fips_list, "popsafe-fips" : extra_fips_list}, dtype="string")
516+
# Normal fips codes and CHNG fips codes are the same for high-population counties.
517+
extra_fips_df = pd.DataFrame({"fips" : extra_fips_list, "chng-fips" : extra_fips_list}, dtype="string")
518518

519519
# Combine high-pop and low-pop counties.
520520
pd.concat(
521521
[county_groups, extra_fips_df]
522522
).sort_values(
523-
["fips", "popsafe-fips"]
523+
["fips", "chng-fips"]
524524
).to_csv(
525-
join(OUTPUT_DIR, FIPS_POPSAFEFIPS_OUT_FILENAME), index=False
525+
join(OUTPUT_DIR, FIPS_CHNGFIPS_OUT_FILENAME), index=False
526526
)
527527

528528

529-
def derive_popsafefips_state_crosswalk():
530-
"""Build a crosswalk table for FIPS to pop-safe fips."""
529+
def derive_chngfips_state_crosswalk():
530+
"""Build a crosswalk table for FIPS to CHNG FIPS."""
531531
if not isfile(join(OUTPUT_DIR, FIPS_STATE_OUT_FILENAME)):
532532
derive_fips_state_crosswalk()
533533

534-
if not isfile(join(OUTPUT_DIR, FIPS_POPSAFEFIPS_OUT_FILENAME)):
535-
derive_fips_popsafefips_crosswalk()
534+
if not isfile(join(OUTPUT_DIR, FIPS_CHNGFIPS_OUT_FILENAME)):
535+
derive_fips_chngfips_crosswalk()
536536

537-
fips_to_group = pd.read_csv(join(OUTPUT_DIR, FIPS_POPSAFEFIPS_OUT_FILENAME), dtype="string", index_col=False)
537+
fips_to_group = pd.read_csv(join(OUTPUT_DIR, FIPS_CHNGFIPS_OUT_FILENAME), dtype="string", index_col=False)
538538
fips_to_state = pd.read_csv(join(OUTPUT_DIR, FIPS_STATE_OUT_FILENAME), dtype="string", index_col=False)
539539

540540
group_to_state = fips_to_group.join(
@@ -543,9 +543,9 @@ def derive_popsafefips_state_crosswalk():
543543
columns = "fips"
544544
).drop_duplicates(
545545
).sort_values(
546-
["popsafe-fips", "state_code"]
546+
["chng-fips", "state_code"]
547547
)
548-
group_to_state.to_csv(join(OUTPUT_DIR, POPSAFEFIPS_STATE_OUT_FILENAME), index=False)
548+
group_to_state.to_csv(join(OUTPUT_DIR, CHNGFIPS_STATE_OUT_FILENAME), index=False)
549549

550550

551551
def clear_dir(dir_path: str):
@@ -574,5 +574,5 @@ def clear_dir(dir_path: str):
574574
derive_zip_population_table()
575575
derive_fips_hhs_crosswalk()
576576
derive_zip_hhs_crosswalk()
577-
derive_fips_popsafefips_crosswalk()
578-
derive_popsafefips_state_crosswalk()
577+
derive_fips_chngfips_crosswalk()
578+
derive_chngfips_state_crosswalk()

_delphi_utils_python/delphi_utils/data/2019/popsafe-fips_state_table.csv renamed to _delphi_utils_python/delphi_utils/data/2019/chng-fips_state_table.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
popsafe-fips,state_code,state_id,state_name
1+
chng-fips,state_code,state_id,state_name
22
01000,01,al,Alabama
33
01001,01,al,Alabama
44
01003,01,al,Alabama

_delphi_utils_python/delphi_utils/data/2019/fips_popsafe-fips_table.csv renamed to _delphi_utils_python/delphi_utils/data/2019/fips_chng-fips_table.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
fips,popsafe-fips
1+
fips,chng-fips
22
01000,01000
33
01001,01001
44
01003,01003

_delphi_utils_python/delphi_utils/data/2020/popsafe-fips_state_table.csv renamed to _delphi_utils_python/delphi_utils/data/2020/chng-fips_state_table.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
popsafe-fips,state_code,state_id,state_name
1+
chng-fips,state_code,state_id,state_name
22
01000,01,al,Alabama
33
01001,01,al,Alabama
44
01003,01,al,Alabama

_delphi_utils_python/delphi_utils/data/2020/fips_popsafe-fips_table.csv renamed to _delphi_utils_python/delphi_utils/data/2020/fips_chng-fips_table.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
fips,popsafe-fips
1+
fips,chng-fips
22
01000,01000
33
01001,01001
44
01003,01003

_delphi_utils_python/delphi_utils/geomap.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class GeoMapper: # pylint: disable=too-many-public-methods
4141
- [x] fips -> megacounty
4242
- [x] fips -> hrr
4343
- [x] fips -> hhs
44-
- [x] fips -> popsafe-fips
45-
- [x] popsafe-fips -> state : unweighted
44+
- [x] fips -> chng-fips
45+
- [x] chng-fips -> state : unweighted
4646
- [x] nation
4747
- [ ] zip -> dma (postponed)
4848
@@ -82,15 +82,15 @@ class GeoMapper: # pylint: disable=too-many-public-methods
8282
"hhs": "zip_hhs_table.csv"
8383
},
8484
"fips": {
85-
"popsafe-fips": "fips_popsafe-fips_table.csv",
85+
"chng-fips": "fips_chng-fips_table.csv",
8686
"zip": "fips_zip_table.csv",
8787
"hrr": "fips_hrr_table.csv",
8888
"msa": "fips_msa_table.csv",
8989
"pop": "fips_pop.csv",
9090
"state": "fips_state_table.csv",
9191
"hhs": "fips_hhs_table.csv",
9292
},
93-
"popsafe-fips": {"state": "popsafe-fips_state_table.csv"},
93+
"chng-fips": {"state": "chng-fips_state_table.csv"},
9494
"state": {"state": "state_codes_table.csv"},
9595
"state_code": {
9696
"hhs": "state_code_hhs_table.csv",
@@ -169,7 +169,7 @@ def _load_geo_values(self, geo_type):
169169

170170
@staticmethod
171171
def convert_fips_to_mega(data, fips_col="fips", mega_col="megafips"):
172-
"""Convert fips or popsafe-fips string to a megafips string."""
172+
"""Convert fips or chng-fips string to a megafips string."""
173173
data = data.copy()
174174
data[mega_col] = data[fips_col].astype(str).str.zfill(5)
175175
data[mega_col] = data[mega_col].str.slice_replace(start=2, stop=5, repl="000")
@@ -234,8 +234,8 @@ def add_geocode(
234234
"""Add a new geocode column to a dataframe.
235235
236236
Currently supported conversions:
237-
- fips -> state_code, state_id, state_name, zip, msa, hrr, nation, hhs, popsafe-fips
238-
- popsafe-fips -> state_code, state_id, state_name
237+
- fips -> state_code, state_id, state_name, zip, msa, hrr, nation, hhs, chng-fips
238+
- chng-fips -> state_code, state_id, state_name
239239
- zip -> state_code, state_id, state_name, fips, msa, hrr, nation, hhs
240240
- jhu_uid -> fips
241241
- state_x -> state_y (where x and y are in {code, id, name}), nation
@@ -245,10 +245,10 @@ def add_geocode(
245245
---------
246246
df: pd.DataFrame
247247
Input dataframe.
248-
from_code: {'fips', 'popsafe-fips', 'zip', 'jhu_uid', 'state_code',
248+
from_code: {'fips', 'chng-fips', 'zip', 'jhu_uid', 'state_code',
249249
'state_id', 'state_name'}
250250
Specifies the geocode type of the data in from_col.
251-
new_code: {'fips', 'popsafe-fips', 'zip', 'state_code', 'state_id',
251+
new_code: {'fips', 'chng-fips', 'zip', 'state_code', 'state_id',
252252
'state_name', 'hrr', 'msa', 'hhs'}
253253
Specifies the geocode type in new_col.
254254
from_col: str, default None
@@ -276,7 +276,7 @@ def add_geocode(
276276
state_codes = ["state_code", "state_id", "state_name"]
277277

278278
if not is_string_dtype(df[from_col]):
279-
if from_code in ["fips", "zip", "popsafe-fips"]:
279+
if from_code in ["fips", "zip", "chng-fips"]:
280280
df[from_col] = df[from_col].astype(str).str.zfill(5)
281281
else:
282282
df[from_col] = df[from_col].astype(str)
@@ -348,8 +348,8 @@ def replace_geocode(
348348
"""Replace a geocode column in a dataframe.
349349
350350
Currently supported conversions:
351-
- fips -> popsafe-fips, state_code, state_id, state_name, zip, msa, hrr, nation
352-
- popsafe-fips -> state_code, state_id, state_name
351+
- fips -> chng-fips, state_code, state_id, state_name, zip, msa, hrr, nation
352+
- chng-fips -> state_code, state_id, state_name
353353
- zip -> state_code, state_id, state_name, fips, msa, hrr, nation
354354
- jhu_uid -> fips
355355
- state_x -> state_y (where x and y are in {code, id, name}), nation
@@ -463,7 +463,7 @@ def fips_to_megacounty(
463463
mega_col="megafips",
464464
count_cols=None,
465465
):
466-
"""Convert and aggregate from FIPS or popsafe-fips to megaFIPS.
466+
"""Convert and aggregate from FIPS or chng-fips to megaFIPS.
467467
468468
Parameters
469469
---------
@@ -565,15 +565,15 @@ def get_geos_within(self, container_geocode, contained_geocode_type, container_g
565565
Supports these 4 combinations:
566566
- all states within a nation
567567
- all counties within a state
568-
- all popsafe counties within a state
568+
- all CHNG counties+county groups within a state
569569
- all states within an hhs region
570570
571571
Parameters
572572
----------
573573
container_geocode: str
574574
Instance of nation/state/hhs to find the sub-regions of
575575
contained_geocode_type: str
576-
The subregion type to retrieve. One of "state", "county", "fips", "popsafe-fips"
576+
The subregion type to retrieve. One of "state", "county", "fips", "chng-fips"
577577
container_geocode_type: str
578578
The parent region type. One of "state", "nation", "hhs"
579579
@@ -590,7 +590,7 @@ def get_geos_within(self, container_geocode, contained_geocode_type, container_g
590590
crosswalk_state = self._crosswalks["fips"]["state"]
591591
fips_hhs = crosswalk_hhs[crosswalk_hhs["hhs"] == container_geocode]["fips"]
592592
return set(crosswalk_state[crosswalk_state["fips"].isin(fips_hhs)]["state_id"])
593-
elif (contained_geocode_type in ("county", "fips", "popsafe-fips") and
593+
elif (contained_geocode_type in ("county", "fips", "chng-fips") and
594594
container_geocode_type == "state"):
595595
contained_geocode_type = self.as_mapper_name(contained_geocode_type)
596596
crosswalk = self._crosswalks[contained_geocode_type]["state"]
@@ -600,4 +600,4 @@ def get_geos_within(self, container_geocode, contained_geocode_type, container_g
600600
raise ValueError("(contained_geocode_type, container_geocode_type) was "
601601
f"({contained_geocode_type}, {container_geocode_type}), but "
602602
"must be one of (state, nation), (state, hhs), (county, state)"
603-
", (fips, state), (popsafe-fips, state)")
603+
", (fips, state), (chng-fips, state)")

_delphi_utils_python/tests/test_geomap.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ def test_load_fips_msa_table(self, geomapper):
190190
msa_data = geomapper.get_crosswalk(from_code="fips", to_code="msa")
191191
assert tuple(msa_data.columns) == ("fips", "msa")
192192

193-
def test_load_fips_popsafefips_table(self, geomapper):
194-
popsafe_data = geomapper.get_crosswalk(from_code="fips", to_code="popsafe-fips")
195-
assert tuple(popsafe_data.columns) == ("fips", "popsafe-fips")
193+
def test_load_fips_chngfips_table(self, geomapper):
194+
chngfips_data = geomapper.get_crosswalk(from_code="fips", to_code="chng-fips")
195+
assert tuple(chngfips_data.columns) == ("fips", "chng-fips")
196196

197197
def test_load_jhu_uid_fips_table(self, geomapper):
198198
jhu_data = geomapper.get_crosswalk(from_code="jhu_uid", to_code="fips")
@@ -230,7 +230,7 @@ def test_megacounty(self, geomapper):
230230
}
231231
)
232232
pd.testing.assert_frame_equal(new_data.set_index("megafips").sort_index(axis=1), expected_df.set_index("megafips").sort_index(axis=1))
233-
# popsafe-county should have the same behavior when converting to megacounties.
233+
# chng-fips should have the same behavior when converting to megacounties.
234234
mega_county_groups = self.mega_data_3.copy()
235235
mega_county_groups.fips.replace({1125:"01g01"}, inplace = True)
236236
new_data = geomapper.fips_to_megacounty(self.mega_data_3, 4, 1)
@@ -246,7 +246,7 @@ def test_megacounty(self, geomapper):
246246
}
247247
)
248248
pd.testing.assert_frame_equal(new_data.set_index("megafips").sort_index(axis=1), expected_df.set_index("megafips").sort_index(axis=1))
249-
# popsafe-county should have the same behavior when converting to megacounties.
249+
# chng-fips should have the same behavior when converting to megacounties.
250250
mega_county_groups = self.mega_data_3.copy()
251251
mega_county_groups.fips.replace({1123:"01g01"}, inplace = True)
252252
new_data = geomapper.fips_to_megacounty(self.mega_data_3, 4, 1, thr_col="count")
@@ -260,7 +260,7 @@ def test_add_population_column(self, geomapper):
260260
with pytest.raises(ValueError):
261261
new_data = geomapper.add_population_column(self.zip_data, "hrr")
262262
with pytest.raises(ValueError):
263-
new_data = geomapper.add_population_column(self.zip_data, "popsafe-fips")
263+
new_data = geomapper.add_population_column(self.zip_data, "chng-fips")
264264
new_data = geomapper.add_population_column(self.fips_data_5, "fips")
265265
assert new_data.shape == (4, 5)
266266
new_data = geomapper.add_population_column(self.state_data, "state_code")
@@ -302,22 +302,22 @@ def test_add_geocode(self, geomapper):
302302
)
303303
)
304304

305-
# fips -> popsafe-fips
306-
new_data = geomapper.add_geocode(self.fips_data_5, "fips", "popsafe-fips")
307-
assert sorted(list(new_data["popsafe-fips"])) == ['01123', '18181', '48g19', '72003']
308-
assert new_data["popsafe-fips"].size == self.fips_data_5.fips.size
309-
new_data = geomapper.replace_geocode(self.fips_data_5, "fips", "popsafe-fips")
310-
assert sorted(list(new_data["popsafe-fips"])) == ['01123', '18181', '48g19', '72003']
311-
assert new_data["popsafe-fips"].size == self.fips_data_5.fips.size
312-
313-
# popsafe-fips -> state_id
314-
new_data = geomapper.replace_geocode(self.fips_data_5, "fips", "popsafe-fips")
315-
new_data2 = geomapper.add_geocode(new_data, "popsafe-fips", "state_id")
305+
# fips -> chng-fips
306+
new_data = geomapper.add_geocode(self.fips_data_5, "fips", "chng-fips")
307+
assert sorted(list(new_data["chng-fips"])) == ['01123', '18181', '48g19', '72003']
308+
assert new_data["chng-fips"].size == self.fips_data_5.fips.size
309+
new_data = geomapper.replace_geocode(self.fips_data_5, "fips", "chng-fips")
310+
assert sorted(list(new_data["chng-fips"])) == ['01123', '18181', '48g19', '72003']
311+
assert new_data["chng-fips"].size == self.fips_data_5.fips.size
312+
313+
# chng-fips -> state_id
314+
new_data = geomapper.replace_geocode(self.fips_data_5, "fips", "chng-fips")
315+
new_data2 = geomapper.add_geocode(new_data, "chng-fips", "state_id")
316316
assert new_data2["state_id"].unique().size == 4
317317
assert new_data2["state_id"].size == self.fips_data_5.fips.size
318318
assert sorted(list(new_data2["state_id"])) == ['al', 'in', 'pr', 'tx']
319319

320-
new_data2 = geomapper.replace_geocode(new_data, "popsafe-fips", "state_id")
320+
new_data2 = geomapper.replace_geocode(new_data, "chng-fips", "state_id")
321321
assert new_data2["state_id"].unique().size == 4
322322
assert new_data2["state_id"].size == 4
323323
assert sorted(list(new_data2["state_id"])) == ['al', 'in', 'pr', 'tx']
@@ -395,20 +395,20 @@ def test_get_geos(self, geomapper):
395395
assert geomapper.get_geo_values("nation") == {"us"}
396396
assert geomapper.get_geo_values("hhs") == set(str(i) for i in range(1, 11))
397397
assert len(geomapper.get_geo_values("fips")) == 3236
398-
assert len(geomapper.get_geo_values("popsafe-fips")) == 2711
398+
assert len(geomapper.get_geo_values("chng-fips")) == 2711
399399
assert len(geomapper.get_geo_values("state_id")) == 60
400400
assert len(geomapper.get_geo_values("zip")) == 32976
401401

402402
def test_get_geos_2019(self, geomapper_2019):
403403
assert len(geomapper_2019.get_geo_values("fips")) == 3235
404-
assert len(geomapper_2019.get_geo_values("popsafe-fips")) == 2710
404+
assert len(geomapper_2019.get_geo_values("chng-fips")) == 2710
405405

406406
def test_get_geos_within(self, geomapper):
407407
assert len(geomapper.get_geos_within("us","state","nation")) == 60
408408
assert len(geomapper.get_geos_within("al","county","state")) == 68
409409
assert len(geomapper.get_geos_within("al","fips","state")) == 68
410410
assert geomapper.get_geos_within("al","fips","state") == geomapper.get_geos_within("al","county","state")
411-
assert len(geomapper.get_geos_within("al","popsafe-fips","state")) == 66
411+
assert len(geomapper.get_geos_within("al","chng-fips","state")) == 66
412412
assert len(geomapper.get_geos_within("4","state","hhs")) == 8
413413
assert geomapper.get_geos_within("4","state","hhs") == {'al', 'fl', 'ga', 'ky', 'ms', 'nc', "tn", "sc"}
414414

0 commit comments

Comments
 (0)