feat(postcodes/PR): 132 Puerto Rico ZIPs (#1039)#1523
Merged
Conversation
Adds Puerto Rico's 132 ZIP codes derived from the US Census ZCTA
data already shipped to US.json (state_code='PR').
Why
---
PR uses US ZIP codes in 006xx-007xx + 009xx ranges, but CSC also
represents Puerto Rico as its own country (iso2=PR, country_id=178)
with 78 municipalities as states. This importer mirrors the same
codes into PR.json under the PR country namespace, FK'd to nearest
PR municipality.
Coverage
--------
- 132 ZIPs / 100% state FK
- 67 of 78 CSC PR municipalities covered (the 11 absent municipalities
have no ZIP centroid in their territory in the Census ZCTA file)
State FK strategy
-----------------
Centroid-distance matching: for each PR ZIP centroid, find the
nearest PR city in cities/PR.json (78 municipalities, 1:1 with
CSC PR states), use that city's state_id.
License
-------
Original source: US Census ZCTA Gazetteer (CC-0, public domain).
Each row: source: "us-census-via-pr-mirror"
Validation
----------
- python3 -m py_compile passes
- 100% regex match (^00[679]\d{2}(?:-\d{4})?$)
- 100% state_id valid + state.country_id == 178 + state_code agrees
- No auto-managed fields (id, created_at, updated_at, flag)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
CSC Validation ReportPR Format
Labels applied: Schema Validation (132 records)✅ All records passed validation Cross-Reference Validation✅ 264 reference(s) verified Geo-Bounds Check✅ All 132 coordinate(s) within expected country bounds Source URL Verification✅ 1 source URL(s) accessible ✅ All checks passed | Status: Ready for review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
US.jsoninto PR's own country namespace for Can we add a postcode for this? #1039Source
contributions/postcodes/US.jsonunderstate_code='PR'PR.jsonso consumers querying bycountry_code='PR'get the data directlyWhy
PR uses US ZIP codes (006xx, 007xx, 009xx) but CSC also represents Puerto Rico as its own country (iso2=PR, country_id=178) with 78 municipalities as states. Without this mirror, postcode lookups for PR would return empty.
State FK strategy
Centroid-distance matching: for each PR ZIP centroid (lat/lng from Census), find the nearest PR municipality in
cities/PR.json(78 entries, 1:1 with CSC PR states), use that municipality's state_id.11 of 78 PR municipalities have no ZIP centroid in their territory — they're absent from the source.
Test plan
python3 -m py_compile bin/scripts/sync/import_puerto_rico_postcodes.py^00[679]\d{2}(?:-\d{4})?$id,created_at,updated_at,flag)🤖 Generated with Claude Code