Skip to content

Commit 1593e47

Browse files
committed
Add describe recommendation to KeyError message
1 parent 5a8125e commit 1593e47

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cf_xarray/accessor.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,9 @@ def __getitem__(self, key):
436436
elif key in _CELL_MEASURES:
437437
raise NotImplementedError("measures not implemented for Dataset yet.")
438438
else:
439-
raise KeyError(f"Dataset.cf does not understand the key {key}")
439+
raise KeyError(
440+
f"Dataset.cf does not understand the key {key!r}. Use Dataset.cf.describe() to see a list of key names that can be interpreted."
441+
)
440442

441443

442444
@xr.register_dataarray_accessor("cf")
@@ -448,4 +450,6 @@ def __getitem__(self, key):
448450
elif key in _CELL_MEASURES:
449451
return self._obj[_get_measure(self._obj, key)]
450452
else:
451-
raise KeyError(f"DataArray.cf does not understand the key {key}")
453+
raise KeyError(
454+
f"DataArray.cf does not understand the key {key!r}. Use DataArray.cf.describe() to see a list of key names that can be interpreted."
455+
)

0 commit comments

Comments
 (0)