-
Notifications
You must be signed in to change notification settings - Fork 43
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
Add path to error message in map_over_subtree #264
Add path to error message in map_over_subtree #264
Conversation
datatree/mapping.py
Outdated
return func(*args, **kwargs) | ||
except Exception as e: | ||
# Add the context information to the error message | ||
e.add_note(f"Raised whilst mapping function over node with path {path}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding notes to exceptions is a new feature in python 3.11.
Perhaps we should wait before merging this? If I understand xarray's deprecation policy correctly then 3.11 will only be the minimum supported version of python 24 months after 3.11 is released, which is 12 months from now...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could use a helper for this:
def add_note(err: BaseException, msg: str) -> None:
# TODO: remove once python 3.10 can be dropped
if sys.version_info < (3, 11):
err.__notes__ = getattr(err, "__notes__", []) + [msg]
else:
err.add_note(msg)
…a info in the error message
for more information, see https://pre-commit.ci
…omNicholas/datatree into error_context_map_over_subtree
for more information, see https://pre-commit.ci
…omNicholas/datatree into error_context_map_over_subtree
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
…omNicholas/datatree into error_context_map_over_subtree
…#264 * test * implementation * formatting * add version check, if not using 3.11 then you just won't get the extra info in the error message * whatsnew * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * use better helper function * xfail test, because this does actually work... --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
map_over_subtree
#190, and would have helped with Error in datatree.DataTree.sel when attributes are set #262pre-commit run --all-files
New functions/methods are listed inapi.rst
docs/source/whats-new.rst