Format UK school postcodes #397
Merged
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.
Context
UK postcode data is used in our reporting tools in order to measure how effective we are at reaching deprived areas (using the IMD / Indices of Multiple Deprivation: https://www.gov.uk/government/collections/english-indices-of-deprivation). This is a key part our programme impact monitoring work.
The IMD lookup relies on a correctly formatted postcode as defined by the NSPL (National Statistics Postcode Lookup) data: 2-4 char outward code, a space, then a 3-char inward code.
Problem
Postcode validation (as in "is this an actual UK postcode that is definitely in the Royal Mail Postcode Address File / PAF") is suboptimal, as doing so with a regex is a pain and potentially error prone (with the onus to 'fix' a potentially valid postcode being put on the user). We're also currently discounting using an API to look up / validate postcodes, though this may be a valid approach going forwards.
Proposed approach
Whilst we don't want to take a heavy-handed approach to postcode validation, as outlined above, we do want to make sure that any postcode that meets the criteria of being "very likely to be in the PAF and NSPL data sets" is formatted in a way which makes lookups possible (in order to prevent cases such as
CB11NT,CB 11NT):Additional steps
Existing school data will need to have the same transform / corrections applied, something like: