Draft
Conversation
izi-on
commented
Jul 3, 2025
Contributor
Author
|
Before I merge this to main, I will conduct tests on actual addresses in Japan and see how they behave with this new prefix validation for japan EDIT: done |
bf2d835 to
dc42cb9
Compare
[feat] japan zip prefix validation
0198acd to
cfe33aa
Compare
Contributor
|
I am deleting the flag as we prioritizing other validation work for now. This can be revisited and the flag can be re-created https://experiments.shopify.com/flags/12446 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What are you trying to accomplish?
We are trying to implement stricter validation for Japanese postal codes.
...
What approach did you choose and why?
I found a highly credible dataset from GeoPostcodes.
Then, I created a rake task that would read a CSV from this dataset and populate the existing JP.yml with valid zone prefixes.
The impact of these changes
We can now perform naive postal code validation based off purely the zone.
Testing
For Shopify reviewers, you can compare the results to that of another rake task in
country-db:simply run
rake "postal:codes:import[JP]"in country-db and compare the modified JP.yml to this
You will notice that this dataset is more complete
Potential question you might ask: why are there so many postal code prefixes for some zones?
That is because the dataset is such, and I believe this is entirely valid. Let's take an example:
Look at the zip prefixes for JP-02:
'03' and '018-550'
'018-550' seems suspicious, let's investigate. If you open the dataset I linked above, search for "018-55" and notice you will get postal codes in zone JP-02 and JP-05 (018-5511 more specifically). Putting these into google maps:
and notice that they are also correspondingly in JP-02 (Aomori Prefecture) and JP-05 (Akita Prefecture):
I would like for reviewers to test it this out themselves, please pick 5 zip prefixes that seem too long, and test it out yourselves following similar steps as me as written above
Validation
I got a sample of 10k real Japanese addresses (For Shopifolk, I linked the methodology for this in the issue linked to this PR)
Created a jupyter notebook (
jp-prefix-validator.ipynb) that will read the CSV, and validate the zip codes against the zip prefixes in JP.ymlCompiled results (For Shopifolk, I reported the results of this validation in the issue linked to this PR)
Checklist