Skip to content

feat(postcodes/IT): bulk-import 4,678 CAP codes via Istat (#1039)#1436

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

feat(postcodes/IT): bulk-import 4,678 CAP codes via Istat (#1039)#1436
dr5hn merged 1 commit into
masterfrom
feat/postcodes-italy-bulk

Conversation

@dr5hn
Copy link
Copy Markdown
Owner

@dr5hn dr5hn commented Apr 27, 2026

Summary

Adds Italian postcodes via the matteocontrini/comuni-json mirror of Istat's official commune list with CAP.

  1. bin/scripts/sync/import_italy_postcodes.py — pipeline expanding each commune's cap[] array to one record per (cap, commune), picking first-alphabetical commune per unique CAP. State resolution by sigla → state.iso2 with one alias bridge (Aosta AO23).
  2. contributions/postcodes/IT.json4,678 unique CAPs across all 7,904 comuni, 100% state_id resolution.

Multi-CAP cities

City CAPs
Rome 82
Venice 56
Messina 48
Genoa 47
Milan 42

Each CAP gets one record pointing to the canonical commune (matches the Tier-4 "one row per code" contract from #1398).

Validation (zero errors across 4,678 records)

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

License

  • Upstream: Istat (CC-BY 3.0)
  • Mirror: github.com/matteocontrini/comuni-json
  • Each row: source: "istat"

Cumulative postcode coverage after this lands

~223,000 postcode rows across 23 countries.

Refs: #1039

Adds the importer + first run for Italy. Uses the matteocontrini/comuni-json
mirror of Istat's official Italian commune list with postcodes (CAP).

1. bin/scripts/sync/import_italy_postcodes.py — pipeline reading the
   community-maintained UTF-8 JSON. Each commune has a cap[] array (large
   cities like Rome have 80+ CAPs); pipeline expands one row per (cap,
   commune) and picks first commune alphabetically as canonical per code.
   State resolution is direct sigla -> state.iso2 match (RM=Rome, MI=Milan,
   etc.) with one alias bridge: Aosta uses sigla 'AO' but states.json has
   it as the 'Aosta Valley' autonomous region with iso2 '23'.

2. contributions/postcodes/IT.json — 4,678 unique CAPs covering all 7,904
   comuni with 100% state_id resolution.

Multi-CAP cities
- Rome: 82 CAPs
- Venice: 56
- Messina: 48
- Genoa: 47
- Milan: 42
- Each CAP gets one record pointing to the canonical commune name; this
  matches the Tier-4 "one row per code" contract from #1398.

Validation (zero errors across 4,678 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: Istat (CC-BY 3.0)
- Mirror: github.com/matteocontrini/comuni-json
- Each row: source: "istat"

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 10:54
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 4678 records. Large contributions require manual review.

Schema Validation (4678 records)

✅ All records passed validation

Cross-Reference Validation

✅ 9356 reference(s) verified


All checks passed | Status: Ready for review

@dr5hn dr5hn merged commit 21cb337 into master Apr 27, 2026
1 check passed
@dr5hn dr5hn deleted the feat/postcodes-italy-bulk branch April 27, 2026 10:59
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