Skip to content

feat(postcodes/PR): 132 Puerto Rico ZIPs (#1039)#1523

Merged
dr5hn merged 1 commit into
masterfrom
feat/postcodes-puerto-rico
May 5, 2026
Merged

feat(postcodes/PR): 132 Puerto Rico ZIPs (#1039)#1523
dr5hn merged 1 commit into
masterfrom
feat/postcodes-puerto-rico

Conversation

@dr5hn

@dr5hn dr5hn commented May 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Mirrors PR-mapped ZIP codes from already-shipped US.json into PR's own country namespace for Can we add a postcode for this? #1039
  • 132 codes / 100% state FK across 67 of 78 CSC PR municipalities

Source

  • US Census ZCTA Gazetteer (Tier 1, CC-0 public domain) — already shipped to contributions/postcodes/US.json under state_code='PR'
  • This PR derives a companion PR.json so consumers querying by country_code='PR' get the data directly

Why

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
  • All 132 codes match ^00[679]\d{2}(?:-\d{4})?$
  • 100% state_id valid; state.country_id == 178; state_code == state.iso2
  • No auto-managed fields (id, created_at, updated_at, flag)
  • Idempotent merge (re-run produces no diff)

🤖 Generated with Claude Code

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>
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label May 5, 2026
@dosubot dosubot Bot added the enhancement New feature or request label May 5, 2026
@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

CSC Validation Report

PR Format

  • ✅ Description provided
  • ✅ Data source linked
  • ✅ Issue linked (recommended for data changes)
  • ✅ Justification / context provided

Labels applied: data:postcodes

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

@dr5hn dr5hn merged commit cc6fa54 into master May 5, 2026
1 check passed
@dr5hn dr5hn deleted the feat/postcodes-puerto-rico branch May 5, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data:postcodes enhancement New feature or request ready-for-review size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant