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

Guard against methods-terms as sub-categories #89

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions definitions/variable/sdg-indicators/sdg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@
sdg: 2
unit: kcal/cap/day
weight: Population
- Price|Agriculture|Livestock|Index:
- Price|Agriculture|Livestock [Index]:
description: Weighted average price index of livestock
sdg: 2
unit: Index (2020 = 1)
skip-region-aggregation: true
# weight: Agricultural Production|Non-Energy
shape: Price|Agriculture|Livestock|Index
phackstock marked this conversation as resolved.
Show resolved Hide resolved
- Health|Premature Deaths|PM2.5:
description: Number of premature deaths associated with increased health risks from
exposure to air pollution of fine particles with a diameter of 2.5 μm or less (PM2.5)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_legacy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from nomenclature import DataStructureDefinition

LEGACY_PROJECTS = ["navigate", "engage", "shape"]


def test_legacy_variables():
# Check that (new) variables are not referenced as deprecated legacy variables
Expand All @@ -8,7 +10,7 @@ def test_legacy_variables():

legacy_variables = {}
for code, attrs in dsd.variable.items():
for project in ["navigate", "engage"]:
for project in LEGACY_PROJECTS:
if project in attrs.extra_attributes:
legacy_var = attrs.__getattr__(project)
if legacy_var in existing_variables:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_reserved_terms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from nomenclature import DataStructureDefinition

RESERVED_TERMS = ["Index", "Share", "Value", "Volume"]


# TODO: Move this test to the nomenclature `validate-project` utility
# see https://github.com/IAMconsortium/nomenclature/issues/341


def test_variable_ops_as_square_brackets():
phackstock marked this conversation as resolved.
Show resolved Hide resolved
# Check that variables use square brackets for operations
# https://github.com/IAMconsortium/common-definitions/issues/55

dsd = DataStructureDefinition("definitions/", dimensions=["variable"])

error = []
for variable in dsd.variable:
if reserved_terms := [r for r in RESERVED_TERMS if "|" + r in variable]:
error.append(f"Variable '{variable}' -> '... [{''.join(reserved_terms)}]'")
if error:
raise ValueError(
f"Found reserved terms in the following variables:\n{'\n - '.join(error)}"
)
Loading