Skip to content

feat(postcodes/ES): bulk-import 8,124 codes via INE/Correos (#1039)#1437

Merged
dr5hn merged 1 commit into
masterfrom
feat/postcodes-spain-bulk
Apr 27, 2026
Merged

feat(postcodes/ES): bulk-import 8,124 codes via INE/Correos (#1039)#1437
dr5hn merged 1 commit into
masterfrom
feat/postcodes-spain-bulk

Conversation

@dr5hn
Copy link
Copy Markdown
Owner

@dr5hn dr5hn commented Apr 27, 2026

Summary

Adds Spanish postcodes via the walterleonardo mirror of INE/Correos's official mapping.

  1. bin/scripts/sync/import_spain_postcodes.py — pipeline reading 3-column CSV (id, postcode, municipality). Resolves state via the well-known Spanish postal-prefix → ISO2 convention.
  2. contributions/postcodes/ES.json8,124 codes, 100% state_id resolution.

State resolution strategy

Spain's states.json uses license-plate-style ISO codes (A=Alicante, B=Barcelona, M=Madrid, GR=Granada, …) rather than numeric postal prefixes. The pipeline includes the authoritative 52-entry postal-prefix → state-iso2 map:

01 → VI (Álava)        28 → M  (Madrid)        51 → CE (Ceuta)
08 → B  (Barcelona)    35 → GC (Las Palmas)    52 → ML (Melilla)
20 → SS (Gipuzkoa)     38 → TF (Sta Cruz Tenerife)  …

Postal prefixes have been stable since the 1980s; map is authoritative.

Validation (zero errors across 8,124 records)

Check Result
Records 8,124
state_id resolved 100%
Codes matching ^(\d{5})$
FK resolution
state_codestate.iso2 agreement
No auto-managed fields

License

  • Upstream: INE / Correos (open data)
  • Mirror: github.com/walterleonardo/codigos_postales_espa-a
  • Each row: source: "ine"

Cumulative postcode coverage after this lands

~231,000 postcode rows across 24 countries.

Refs: #1039

Adds the importer + first run for Spain. Uses the walterleonardo mirror
of INE/Correos's official codigos-postales-municipios mapping.

1. bin/scripts/sync/import_spain_postcodes.py — pipeline reading the
   3-column header-less CSV (id, postal_code, municipality_name).
   Resolves state via the well-known Spanish postal-prefix to ISO2
   convention (01->VI Álava, 28->M Madrid, 08->B Barcelona, ..., 51->CE
   Ceuta, 52->ML Melilla). states.json uses license-plate-style codes
   (A, B, M, GR, ...) so a hardcoded 52-entry prefix map is the cleanest
   resolution path.

2. contributions/postcodes/ES.json — 8,124 unique postcodes with 100%
   state_id resolution.

State resolution
- 50 provinces + 2 autonomous cities (Ceuta, Melilla) covered
- Postal prefixes 01-52 are stable since 1980s; map is authoritative

Validation (zero errors across 8,124 records)
- All codes match countries.postal_code_regex (^(\\d{5})\$)
- All FKs resolve, all state_codes agree with state.iso2
- No auto-managed fields present

License & attribution
- Upstream: INE/Correos (open data)
- Mirror: github.com/walterleonardo/codigos_postales_espa-a
- Each row: source: "ine"

Refs: #1039

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 27, 2026 11:01
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. enhancement New feature or request labels Apr 27, 2026
@github-actions
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, large-contribution

⚠️ Large Contribution

This PR contains 8124 records. Large contributions require manual review.

Schema Validation (8124 records)

✅ All records passed validation

Cross-Reference Validation

✅ 16248 reference(s) verified


All checks passed | Status: Ready for review

@dr5hn dr5hn merged commit 5154beb into master Apr 27, 2026
1 check passed
@dr5hn dr5hn deleted the feat/postcodes-spain-bulk branch April 27, 2026 11:08
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 large-contribution 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.

2 participants