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

Better error messages for DataTree #9222

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

shoyer
Copy link
Member

@shoyer shoyer commented Jul 9, 2024

KeyError applies some automatic formatting, so it really only makes sense to use raise KeyError(key).

I've also tweaks a few other error messages to use more appropriate types.

@shoyer shoyer requested a review from TomNicholas July 9, 2024 18:12
xarray/core/treenode.py Outdated Show resolved Hide resolved
@TomNicholas TomNicholas added the topic-DataTree Related to the implementation of a DataTree class label Jul 9, 2024
xarray/core/treenode.py Outdated Show resolved Hide resolved
@@ -456,14 +456,14 @@ def _get_item(self: Tree, path: str | NodePath) -> Tree | T_DataArray:
for part in parts:
if part == "..":
if current_node.parent is None:
raise KeyError(f"Could not find node at {path}")
raise KeyError(path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why you've made this error message less informative @shoyer ? The equivalent operation on a Dataset gives a more explicit message:

xr.Dataset()['a']
KeyError: "No variable named 'a'. Variables on the dataset include []"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-DataTree Related to the implementation of a DataTree class topic-error reporting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants