Skip to content

Attributes from parent group not recognized #63

@sfinkens

Description

@sfinkens

Describe the bug
When checking a data tree, xrlint doesn't recognize attributes from the parent group.

To Reproduce

import xarray as xr
import xrlint.all as xrl

# Create data tree
global_attrs = {
    "Conventions": "CF-1.12",
    "title": "My title",
    "references": "DOI:1234",
    "institution": "My institute",
    "source": "My source",
    "comment": "My comment",
    "history": "My history",
}
temp = xr.DataArray(
    [1, 2, 3],
    dims="x",
    attrs={
        "units": "K",
        "long_name": "Air Temperature",
        "standard_name": "air_temperature"
    }
)
x = xr.DataArray(
    [1, 2, 3],
    dims="x",
    attrs={
        "units": "m",
    }
)
mygroup = xr.Dataset(
    {"temp": temp},
    coords={"x": x},
    attrs={"title": "My group"}
)
tree = xr.DataTree.from_dict(
    {
        "/": xr.Dataset(attrs=global_attrs),
        "/mygroup": mygroup
    }
)

# Run linter
linter = xrl.new_linter("recommended")
res = linter.validate(tree)
for msg in res.messages:
    print(msg.node_path, msg.message)

Output:

dt/mygroup/mygroup Missing attribute 'history'.
dt/mygroup/mygroup.data_vars['temp'] Missing attribute 'institution'.
dt/mygroup/mygroup.data_vars['temp'] Missing attribute 'source'.
dt/mygroup/mygroup.data_vars['temp'] Missing attribute 'references'.
dt/mygroup/mygroup.data_vars['temp'] Missing attribute 'comment'.
dt/mygroup/mygroup Missing attribute 'Conventions'.

Expected behavior
No errors because the required attributes are already present in the parent group.

Python Environment

  • operating system: Rocky Linux
  • XRLint version, output of xrlint --version: 0.5.1
  • optional: packages and their versions, output of pip list or conda list:

Additional context
None

Traceback
None

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions