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 countries attribute to the region codelist #374

Conversation

danielhuppmann
Copy link
Member

While working on model-registrations for common-definitions, I noticed that we've not been consistent whether to add a list of countries or ISO3-codes to clearly define model-native regions.

In favor of readability, I'd prefer to use country-names, see for example IAMconsortium/common-definitions#118.

This PR adds an optional countries attribute to the RegionCode class, and validates any names in this list against the nomenclature.countries list.

As a follow-up PR, I suggest that we deprecate the iso3_codes attribute and instead add an alpha_3 property that returns the countries-elements translated to ISO3 codes. This way, we have good readability and consistency in the GitHub repos and anyone still prefering to work with ISO3 codes can still comfortably work with those.

@phackstock
Copy link
Contributor

As a follow-up PR, I suggest that we deprecate the iso3_codes attribute and instead add an alpha_3 property that returns the countries-elements translated to ISO3 codes. This way, we have good readability and consistency in the GitHub repos and anyone still prefering to work with ISO3 codes can still comfortably work with those.

I am on board with that suggestion. We'll just might have to update some instance workflow repositories that are currently using the iso3_codes attribute. That shouldn't prevent us from improving the readability though which this PR does in my opinion.

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.

Couple of suggestions in-line, good to merge otherwise.

"""Verifies that each country name is defined in `nomenclature.countries`."""
if invalid_country_names := set(v) - set(countries.names):
raise ValueError(
f"Region '{info.data['name']}' uses non-standard country name(s): "
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd reference the exact ISO norm that we're using, just "standard" is a little ambiguous in my opinion:

Suggested change
f"Region '{info.data['name']}' uses non-standard country name(s): "
f"Region '{info.data['name']}' uses non-ISO3166-1 compliant country name(s): "

Copy link
Member Author

Choose a reason for hiding this comment

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

We do not strictly follow ISO-3166-1, we use our own adaptation, see
https://github.com/IAMconsortium/nomenclature/blob/main/nomenclature/countries.py.

I added a link to the documentation for clarity.

@@ -4,6 +4,5 @@ repositories:
definitions:
region:
repository: common-definitions
country: true
Copy link
Contributor

Choose a reason for hiding this comment

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

As an alternative you could leave this in and use the pin feature to pin this config to the latest pre-G20 common-definitions revision:

repositories:
  common-definitions:
    url: https://github.com/IAMconsortium/common-definitions.git/
    hash: 4f77be8
definitions:
  region:
    repository: common-definitions
    country: true
  variable:
    repository: common-definitions

Copy link
Member Author

Choose a reason for hiding this comment

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

We do have a separate test for country: true, so I'd rather keep the tests consistent with the latest version of common-definitions to be warned about future conflicts early. There isn't so much extra benefit to the joint test of common-definitions and country: true.

@@ -5,6 +5,5 @@ repositories:
definitions:
region:
repository: common-definitions
country: true
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, to fix the tests you could pin common-definitions:

repositories:
  common-definitions:
    url: https://github.com/IAMconsortium/common-definitions.git/
    hash: 4f77be8
definitions:
  region:
    repository: common-definitions
    country: true
  variable:
    repository: common-definitions

@@ -51,12 +51,6 @@ def test_definition_from_general_config(workflow_folder):
assert "Region A" in obs.region
# imported from https://github.com/IAMconsortium/common-definitions repo
assert "World" in obs.region
# added via general-config definitions
assert "Austria" in obs.region
Copy link
Contributor

Choose a reason for hiding this comment

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

If you introduce the pin for common-definitions, you can bring this one back (I think)

@danielhuppmann danielhuppmann merged commit 08748f5 into IAMconsortium:main Sep 3, 2024
8 checks passed
@danielhuppmann danielhuppmann deleted the feature/region-countries-attribute branch September 3, 2024 06:46
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