Skip to content

Commit

Permalink
Fix valid range with valid min/max check logic
Browse files Browse the repository at this point in the history
Fixes a logic error in valid_range with valid_min/valid_max which
resulted in erroneous results.
  • Loading branch information
benjwadams committed Apr 15, 2024
1 parent b551c2f commit 584f896
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions compliance_checker/cf/cf_1_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,15 +443,19 @@ def check_valid_range_or_valid_min_max_present(self, ds):
total = 0

for variable in ds.variables.values():
if hasattr(variable, "valid_max") and (
hasattr(variable, "valid_min") or hasattr(variable, "valid_range")
):
total = total + 1

fails.append(
f"For the variable {variable.name} the valid_range attribute must not be present "
"if the valid_min and/or valid_max attributes are present",
)
if (hasattr(variable, "valid_max") or
hasattr(variable, "valid_min")):
total += 1
# if there's also valid_range in addition to
# valid_min/valid_max, this is not compliant
if hasattr(variable, "valid_range"):
fails.append(
f"For the variable {variable.name} the valid_range attribute must not be present "
"if the valid_min and/or valid_max attributes are present",
)
# *Just* valid_range should be added to total as well
elif hasattr(variable, "valid_range"):
total += 1

return Result(
BaseCheck.MEDIUM,
Expand Down

0 comments on commit 584f896

Please sign in to comment.