Skip to content

Commit

Permalink
Use pyam.utils.pattern_match for wildcard validation
Browse files Browse the repository at this point in the history
  • Loading branch information
phackstock committed Sep 23, 2024
1 parent 13a025d commit 829a816
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions nomenclature/codelist.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from fnmatch import fnmatch
from pathlib import Path
from textwrap import indent
from typing import ClassVar, Dict, List
Expand All @@ -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

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 829a816

Please sign in to comment.