From 819296535e9bfb51605ad3af1beef479231fa1e3 Mon Sep 17 00:00:00 2001 From: Daniel Huppmann Date: Thu, 17 Aug 2023 15:34:44 +0200 Subject: [PATCH 1/2] Refactor to use revised pyam module structure --- nomenclature/code.py | 5 ++--- nomenclature/validation.py | 3 ++- tests/conftest.py | 3 ++- tests/test_core.py | 3 ++- tests/test_region_aggregation.py | 3 ++- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/nomenclature/code.py b/nomenclature/code.py index ecc618f1..d74661c2 100644 --- a/nomenclature/code.py +++ b/nomenclature/code.py @@ -1,13 +1,12 @@ import json import re -import pyam import pycountry from keyword import iskeyword from pathlib import Path from typing import Any, Dict, List, Optional, Set, Union - from pydantic import BaseModel, Field, validator +from pyam.utils import to_list class Code(BaseModel): """A simple class for a mapping of a "code" to its attributes""" @@ -230,7 +229,7 @@ def check_iso3_codes(cls, v, values) -> List[str]: """Verifies that each ISO3 code is valid according to pycountry library.""" if invalid_iso3_codes := [ iso3_code - for iso3_code in pyam.to_list(v) + for iso3_code in to_list(v) if pycountry.countries.get(alpha_3=iso3_code) is None ]: raise ValueError( diff --git a/nomenclature/validation.py b/nomenclature/validation.py index 58db5b0d..d6e24c1c 100644 --- a/nomenclature/validation.py +++ b/nomenclature/validation.py @@ -1,5 +1,6 @@ import logging -from pyam import IamDataFrame, to_list +from pyam import IamDataFrame +from pyam.utils import to_list # define logger for this script at logging level INFO logger = logging.getLogger(__name__) diff --git a/tests/conftest.py b/tests/conftest.py index da90ba34..d3c2e368 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,7 +2,8 @@ import pytest import shutil import pandas as pd -from pyam import IamDataFrame, IAMC_IDX +from pyam import IamDataFrame +from pyam.utils import IAMC_IDX from nomenclature import DataStructureDefinition diff --git a/tests/test_core.py b/tests/test_core.py index 54e733aa..9f04df6d 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -7,7 +7,8 @@ from nomenclature.core import process from nomenclature.definition import DataStructureDefinition from nomenclature.processor.region import RegionProcessor -from pyam import IAMC_IDX, IamDataFrame, assert_iamframe_equal +from pyam import IamDataFrame, assert_iamframe_equal +from pyam.utils import IAMC_IDX from conftest import TEST_DATA_DIR, add_meta diff --git a/tests/test_region_aggregation.py b/tests/test_region_aggregation.py index c514c39b..b2f60b81 100644 --- a/tests/test_region_aggregation.py +++ b/tests/test_region_aggregation.py @@ -10,7 +10,8 @@ process, ) from nomenclature.error.region import RegionAggregationMappingParsingError -from pyam import IAMC_IDX, IamDataFrame +from pyam import IamDataFrame +from pyam.utils import IAMC_IDX from conftest import TEST_DATA_DIR, clean_up_external_repos From de7b5bd3efcfaa2590475587d5feec1be64be924 Mon Sep 17 00:00:00 2001 From: Daniel Huppmann Date: Thu, 17 Aug 2023 15:49:44 +0200 Subject: [PATCH 2/2] Make black --- nomenclature/code.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nomenclature/code.py b/nomenclature/code.py index d74661c2..499a2a87 100644 --- a/nomenclature/code.py +++ b/nomenclature/code.py @@ -8,6 +8,7 @@ from pyam.utils import to_list + class Code(BaseModel): """A simple class for a mapping of a "code" to its attributes"""