Skip to content
Open
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: 6 additions & 0 deletions cf_xarray/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2039,6 +2039,12 @@ def keys(self) -> set[Hashable]:
varnames.extend(list(self.cell_measures))
varnames.extend(list(self.standard_names))
varnames.extend(list(self.cf_roles))
custom_criteria = ChainMap(*OPTIONS["custom_criteria"])
varnames.extend(
key
for key in custom_criteria
if _get_custom_criteria(self._obj, key, custom_criteria)
)
if isinstance(self._obj, xr.Dataset):
varnames.extend(list(self.grid_mapping_names))
else:
Expand Down
14 changes: 14 additions & 0 deletions cf_xarray/tests/test_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2174,6 +2174,20 @@ def test_custom_criteria() -> None:
assert_identical(ds.cf["temp"], ds["temperature"])


def test_custom_criteria_membership() -> None:
custom_criteria = {
"salt": {"standard_name": "salinity"},
"ssh": {"standard_name": "sea_surface_height"},
}
ds = xr.Dataset({"salinity": ("time", [34.5, 35.0], {"standard_name": "salinity"})})

with cf_xarray.set_options(custom_criteria=custom_criteria):
assert "salt" in ds.cf.keys()
assert "salt" in ds.cf
assert "ssh" not in ds.cf.keys()
assert "ssh" not in ds.cf


@requires_regex
def test_regex_match():
# test that having a global regex expression flag later in the expression will work if
Expand Down