Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #1102

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
- test_requirements.txt

- repo: https://github.com/psf/black
rev: 24.4.2
rev: 24.8.0
hooks:
- id: black
language_version: python3
Expand All @@ -31,12 +31,12 @@ repos:


- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
rev: v0.5.6
hooks:
- id: ruff

- repo: https://github.com/tox-dev/pyproject-fmt
rev: 2.1.3
rev: 2.2.1
hooks:
- id: pyproject-fmt

Expand Down
24 changes: 17 additions & 7 deletions compliance_checker/cf/cf_1_9.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ def check_domain_variables(self, ds: Dataset):
continue
appendix_a_not_recommended_attrs = []
for attr_name in domain_var.ncattrs():
if attr_name in self.appendix_a and "D" not in self.appendix_a[attr_name]["attr_loc"]:
if (
attr_name in self.appendix_a
and "D" not in self.appendix_a[attr_name]["attr_loc"]
):
appendix_a_not_recommended_attrs.append(attr_name)

if appendix_a_not_recommended_attrs:
Expand All @@ -163,21 +166,28 @@ def check_domain_variables(self, ds: Dataset):
# no errors occurred
domain_valid.score += 1


# IMPLEMENTATION CONFORMANCE 5.8 REQUIRED 4/4
if hasattr(domain_var, "cell_measures"):
cell_measures_var_names = regex.findall(r"\b(?:area|volume):\s+(\w+)", domain_var.cell_measures)
cell_measures_var_names = regex.findall(
r"\b(?:area|volume):\s+(\w+)", domain_var.cell_measures,
)
# check exist
for var_name in cell_measures_var_names:
try:
cell_measures_variable = ds.variables[var_name]
except ValueError:
# TODO: what to do here?
continue
domain_coord_var_names = {var_like.name for var_like in domain_coord_vars}
domain_valid.assert_true(set(cell_measures_variable.dimensions).issubset(domain_coord_var_names),
"Variables named in the cell_measures attributes must have a dimensions attribute with "
"values that are a subset of the referring domain variable's dimension attribute")
domain_coord_var_names = {
var_like.name for var_like in domain_coord_vars
}
domain_valid.assert_true(
set(cell_measures_variable.dimensions).issubset(
domain_coord_var_names,
),
"Variables named in the cell_measures attributes must have a dimensions attribute with "
"values that are a subset of the referring domain variable's dimension attribute",
)

results.append(domain_valid.to_result())

Expand Down
10 changes: 6 additions & 4 deletions compliance_checker/tests/test_cf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3258,10 +3258,12 @@ def test_domain(self):
domain_var.cell_measures = "volume: cube_bad"
dataset.createVariable("cube_bad", "f8", ("lon", "lat", "depth", "time"))
results = self.cf.check_domain_variables(dataset)
self.assertTrue("Variables named in the cell_measures attributes must "
"have a dimensions attribute with values that are a "
"subset of the referring domain variable's dimension "
"attribute" in results[0].msgs)
self.assertTrue(
"Variables named in the cell_measures attributes must "
"have a dimensions attribute with values that are a "
"subset of the referring domain variable's dimension "
"attribute" in results[0].msgs,
)
del dataset
dataset = MockTimeSeries()
# domain should be dimensionless -- currently not an error in
Expand Down
Loading