Skip to content

Commit

Permalink
Rename CodeList.invalid_items to validate_items (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
phackstock authored Jan 9, 2023
1 parent 4706d8f commit cac01c4
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions nomenclature/codelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ def keys(self):
def values(self):
return self.mapping.values()

def invalid_items(self, items: List[str]) -> List[str]:
def validate_items(self, items: List[str]) -> List[str]:
"""Validate that a list of items are valid codes
Returns
-------
list
Returns the list of items that are not defined in the codelist
Returns the list of items that are **not** defined in the codelist
"""
return [c for c in items if c not in self.keys()]

Expand Down
2 changes: 1 addition & 1 deletion nomenclature/processor/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def rename_mapping(self) -> Dict[str, str]:
def validate_regions(self, dsd: DataStructureDefinition) -> None:
if hasattr(dsd, "region"):
# invalid = [c for c in self.all_regions if c not in dsd.region]
invalid = dsd.region.invalid_items(self.all_regions)
invalid = dsd.region.validate_items(self.all_regions)
if invalid:
raise RegionNotDefinedError(region=invalid, file=self.file)

Expand Down
2 changes: 1 addition & 1 deletion nomenclature/processor/required_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def validate_with_definition(self, dsd: DataStructureDefinition) -> None:
# check for undefined regions and variables
for dim in ("region", "variable"):
values = self.__getattribute__(dim) or []
invalid = dsd.__getattribute__(dim).invalid_items(values)
invalid = dsd.__getattribute__(dim).validate_items(values)
if invalid:
error_msg += (
f"The following {dim}(s) were not found in the "
Expand Down
2 changes: 1 addition & 1 deletion nomenclature/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def validate(dsd, df, dimensions):

# validation of all other dimensions
for dim in [d for d in dimensions if d != "variable"]:
invalid = dsd.__getattribute__(dim).invalid_items(df.__getattribute__(dim))
invalid = dsd.__getattribute__(dim).validate_items(df.__getattribute__(dim))
if invalid:
log_error(dim, invalid)
error = True
Expand Down

0 comments on commit cac01c4

Please sign in to comment.