Skip to content

Commit 7ff30ac

Browse files
committed
Extend geocode utility to actually support the mappings:
- state_x -> state_y where x,y are in {code, id, name}
1 parent cf6f4c1 commit 7ff30ac

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

_delphi_utils_python/delphi_utils/geomap.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,9 @@ def add_geocode(
305305
)
306306

307307
# state codes are all stored in one table
308-
if new_code in state_codes:
308+
if from_code in state_codes and new_code in state_codes:
309+
crosswalk = self._load_crosswalk(from_code="state", to_code="state")
310+
elif new_code in state_codes:
309311
crosswalk = self._load_crosswalk(from_code=from_code, to_code="state")
310312
crosswalk = crosswalk.rename(
311313
columns={from_code: from_col, new_code: new_col}

_delphi_utils_python/tests/test_geomap.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ def test_add_geocode(self):
382382
new_data2 = gmpr.add_geocode(new_data, "state_code", "hhs_region_number")
383383
assert new_data2["hhs_region_number"].unique().size == 2
384384

385+
# state_name -> state_id
386+
new_data = gmpr.add_geocode(self.zip_data, "zip", "state_name")
387+
new_data2 = gmpr.add_geocode(new_data, "state_name", "state_id")
388+
assert new_data2.shape == (12, 6)
389+
385390
# fips -> nation
386391
new_data = gmpr.replace_geocode(self.fips_data_5, "fips", "nation")
387392
assert new_data.equals(

0 commit comments

Comments
 (0)