Skip to content

Commit 45aebc8

Browse files
baogorekclaude
andcommitted
Normalize at-large district naming: 00 and 98 both map to 01
DC (GEOID 1198, district 98) and at-large states (GEOID XX00, district 00) should all display as XX-01. Previously max(d, 1) only handled 00, producing DC-98.h5 instead of DC-01.h5. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d709386 commit 45aebc8

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

policyengine_us_data/calibration/publish_local_area.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ def build_district_h5(
150150
"""
151151
cd_int = int(cd_geoid)
152152
state_fips = cd_int // 100
153-
district_num = max(cd_int % 100, 1)
153+
district_num = cd_int % 100
154+
if district_num in AT_LARGE_DISTRICTS:
155+
district_num = 1
154156
state_code = STATE_CODES.get(state_fips, str(state_fips))
155157
friendly_name = f"{state_code}-{district_num:02d}"
156158

@@ -224,11 +226,16 @@ def build_city_h5(
224226
return output_path
225227

226228

229+
AT_LARGE_DISTRICTS = {0, 98}
230+
231+
227232
def get_district_friendly_name(cd_geoid: str) -> str:
228233
"""Convert GEOID to friendly name (e.g., '0101' -> 'AL-01')."""
229234
cd_int = int(cd_geoid)
230235
state_fips = cd_int // 100
231-
district_num = max(cd_int % 100, 1)
236+
district_num = cd_int % 100
237+
if district_num in AT_LARGE_DISTRICTS:
238+
district_num = 1
232239
state_code = STATE_CODES.get(state_fips, str(state_fips))
233240
return f"{state_code}-{district_num:02d}"
234241

@@ -327,7 +334,9 @@ def build_and_upload_districts(
327334
for i, cd_geoid in enumerate(cds_to_calibrate):
328335
cd_int = int(cd_geoid)
329336
state_fips = cd_int // 100
330-
district_num = max(cd_int % 100, 1)
337+
district_num = cd_int % 100
338+
if district_num in AT_LARGE_DISTRICTS:
339+
district_num = 1
331340
state_code = STATE_CODES.get(state_fips, str(state_fips))
332341
friendly_name = f"{state_code}-{district_num:02d}"
333342

policyengine_us_data/calibration/stacked_dataset_builder.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,9 @@ def create_sparse_cd_stacked_dataset(
919919
# Convert GEOID to friendly name: 3705 -> NC-05
920920
cd_int = int(cd_geoid)
921921
state_fips = cd_int // 100
922-
district_num = max(cd_int % 100, 1)
922+
district_num = cd_int % 100
923+
if district_num in (0, 98):
924+
district_num = 1
923925
state_code = STATE_CODES.get(state_fips, str(state_fips))
924926
friendly_name = f"{state_code}-{district_num:02d}"
925927

0 commit comments

Comments
 (0)