Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a module for translating between country names and alpha-2/3 codes #263

Merged
merged 11 commits into from
Jul 20, 2023

Conversation

danielhuppmann
Copy link
Member

Per a suggestion by @willu47, this PR adds a shim of the pycountry.countries feature offering a simple translation between country names (as commonly used in the modelling community) and alpha-3/alpha-2 codes including the special use of alpha-2 by the European Commission.

@danielhuppmann
Copy link
Member Author

@willu47, this PR implements an all-directions ISO2/ISO3-country-name mapping similar to the pycountry package, i.e.,

from nomenclature import countries

name = countries.get(alpha_3="...").name
alpha_3 = countries.get(name="...").alpha_3

From my point of view, it's preferable to have one versatile mapping rather than numerous distinct country_name_to_iso3 and iso3_to_country_name dictionaries - or do you see this differently?

Copy link
Contributor

@phackstock phackstock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.
Couple of comments in line but nothing major.

docs/api/countries.rst Outdated Show resolved Hide resolved
docs/api/countries.rst Show resolved Hide resolved
nomenclature/__init__.py Outdated Show resolved Hide resolved
docs/api/countries.rst Show resolved Hide resolved
nomenclature/codelist.py Outdated Show resolved Hide resolved
nomenclature/countries.py Show resolved Hide resolved
obj = self.data_class(**entry)
self.objects.append(obj)

for key, value in entry.items():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried fully wrapping my head around what's going on here but failed to grasp all the details.
Since it's adapted from pycountry.db.Database I assume this is fine.

nomenclature/countries.py Show resolved Hide resolved
tests/test_countries.py Show resolved Hide resolved
Copy link
Contributor

@phackstock phackstock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates @danielhuppmann.
Good to be merged from my side.

@danielhuppmann danielhuppmann merged commit f9bb77d into IAMconsortium:main Jul 20, 2023
@danielhuppmann danielhuppmann deleted the module/countries branch July 20, 2023 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants