From 829a81622ac9ea8e700eaca786b638a6dfc38bbd Mon Sep 17 00:00:00 2001 From: Philip Hackstock <20710924+phackstock@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:11:44 +0200 Subject: [PATCH] Use pyam.utils.pattern_match for wildcard validation --- nomenclature/codelist.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nomenclature/codelist.py b/nomenclature/codelist.py index 1d0b13a6..a7f0d066 100644 --- a/nomenclature/codelist.py +++ b/nomenclature/codelist.py @@ -1,5 +1,4 @@ import logging -from fnmatch import fnmatch from pathlib import Path from textwrap import indent from typing import ClassVar, Dict, List @@ -8,7 +7,7 @@ import pandas as pd import yaml from pyam import IamDataFrame -from pyam.utils import is_list_like, write_sheet +from pyam.utils import is_list_like, write_sheet, pattern_match from pydantic import BaseModel, ValidationInfo, field_validator from pydantic_core import PydanticCustomError @@ -117,7 +116,8 @@ def validate_items(self, items: List[str]) -> List[str]: list Returns the list of items that are **not** defined in the codelist """ - return [item for item in items if not any(fnmatch(item, code) for code in self)] + matches = pattern_match(pd.Series(items), self.keys()) + return [item for item, match in zip(items, matches) if not match] @classmethod def replace_tags(