Skip to content

feat(postcodes/FI): 3,748 Posti.fi PCF codes (#1039)#1513

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

feat(postcodes/FI): 3,748 Posti.fi PCF codes (#1039)#1513
dr5hn merged 1 commit into
masterfrom
feat/postcodes-finland

Conversation

@dr5hn
Copy link
Copy Markdown
Owner

@dr5hn dr5hn commented May 4, 2026

Summary

  • Imports Finland's official 5-digit Posti postcodes (3,748) for Can we add a postcode for this? #1039
  • 100% state FK resolution across all 18 mainland Finnish maakunta
  • Resolves the research-doc Tier B note Posti's PCF_*.dat file is canonical but URL is date-stamped — known difficult per memory

Source

  • Posti.fi PCF — Finland's official daily postal code file (canonical)
  • URL pattern: https://www.posti.fi/webpcode/unzip/PCF_<YYYYMMDD>.dat
  • The importer probes back ~30 days from today via HEAD requests to find the freshest available file
  • License: Posti's terms — free redistribution permitted with attribution (Tier 5 per Can we add a postcode for this? #1039 policy)

Format

Fixed-width ISO-8859-1, 220 chars/record. Importer parses positional fields per Posti's published spec (record id, postal code, postal name FI/SV, abbreviations, effective date, region code, region names FI/SV, municipality code, municipality names FI/SV, language).

State FK strategy

18-entry FI_REGION_TO_ISO2 maps Finnish maakunta names to CSC iso2:

  • Direct match for 17 mainland regions
  • Helsinki-Uusimaa (NUTS sub-region) → CSC 18 Uusimaa per ISO 3166-2:FI

Åland is shipped separately

The 37 source records with region FI200 / Ahvenanmaa belong to Åland Islands, which is a separate CSC country (AX, country_id=2). They will be shipped via a companion AX importer.

Distribution (top 5)

iso2 region rows
18 Uusimaa 673
10 Lapland 305
11 Pirkanmaa 291
14 Northern Ostrobothnia 261
15 Northern Savonia 253

All 18 mainland regions covered.

Test plan

  • python3 -m py_compile bin/scripts/sync/import_finland_postcodes.py
  • All 3,748 codes match ^(?:FI)*\d{5}$
  • 100% state_id valid; state.country_id == 74; 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 Finland's official 5-digit postal codes from Posti.fi's daily
PCF (postal code file) export.

Why
---
Closes the FI gap on issue #1039. The previously-tracked
launis/areadata source was a wrapper-only package with no bulk
export. Posti's PCF DAT file is the canonical source but the URL is
date-stamped (memory: known difficult). Auto-resolution of the
URL via 30-day-back HEAD probe makes this a clean static fetch.

Coverage
--------
- 3,748 codes / 100% state FK
- All 18 mainland Finnish maakunta covered
- 37 Åland records skipped — they ship to AX (Åland Islands, separate
  CSC country) via a companion importer

Source pipeline
---------------
1. URL probe back ~30 days for the latest PCF_<YYYYMMDD>.dat
2. ISO-8859-1 decode (Posti standard)
3. Fixed-width parse (220 chars/record per Posti spec)
4. Region name -> CSC iso2 via FI_REGION_TO_ISO2 (18-entry hand map
   — Finnish maakunta names; Helsinki-Uusimaa NUTS sub-region merges
   into Uusimaa per ISO 3166-2:FI)

License
-------
Source: Posti.fi PCF (free redistribution permitted with attribution).
Each row: source: "posti-fi-pcf"
Tier 5 per #1039 license-tier policy.

Validation
----------
- python3 -m py_compile passes
- 100% regex match (^(?:FI)*\d{5}$)
- 100% state_id valid + state.country_id == 74 + 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 4, 2026
@dosubot dosubot Bot added the enhancement New feature or request label May 4, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

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 3748 records. Large contributions require manual review.

Schema Validation (3748 records)

✅ All records passed validation

Cross-Reference Validation

✅ 7496 reference(s) verified

Source URL Verification

✅ 1 source URL(s) accessible


0 errors, 1 warning(s) | Status: Ready for review (with warnings)

@dr5hn dr5hn merged commit 4534958 into master May 5, 2026
1 check passed
@dr5hn dr5hn deleted the feat/postcodes-finland 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 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.

1 participant