Add get_admin1_codes() for first-level administrative divisions - #48
Open
cvl01 wants to merge 1 commit into
Open
Add get_admin1_codes() for first-level administrative divisions#48cvl01 wants to merge 1 commit into
cvl01 wants to merge 1 commit into
Conversation
Adds the GeoNames admin1CodesASCII.txt dataset as a new admin1.json data file, keyed by the composite code <countrycode>.<admin1code> (e. g. US.CA). Since city records store countrycode and admin1code separately, the composite key allows resolving those references to the admin1 name and geonameid.
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.
Summary
Adds support for the GeoNames first-level administrative division dataset (
admin1CodesASCII.txt), exposed via a newGeonamesCache.get_admin1_codes()method.Design
The returned dictionary is keyed by the composite code
<countrycode>.<admin1code>, e. g.US.CA, matching the format used in the GeoNames source file. This is the headline benefit of the composite key: city records storecountrycodeandadmin1codeas separate fields, so their admin1 references are directly resolvable:Each record contains
name,asciinameandgeonameid.Changes
bin/download_data.py: downloadadmin1CodesASCII.txtbin/admin1.py: new generator producingadmin1.jsonMakefile: run the new generator in thejsontargetgeonamescache/types.py: newAdmin1TypedDict andAdmin1CodeStrkey aliasgeonamescache/__init__.py: newget_admin1_codes()methodVerification
pytest: all new and existing tests pass (the new tests cover key lookup, dataset size and resolving a city's admin1 reference)ruff checkandmypy geonamescache testspass