diff --git a/xarray/core/datatree_mapping.py b/xarray/core/datatree_mapping.py index fba88ea6ad2..c378371c98a 100644 --- a/xarray/core/datatree_mapping.py +++ b/xarray/core/datatree_mapping.py @@ -160,8 +160,8 @@ def _check_single_set_return_values(path_to_node: str, obj: Any) -> int | None: isinstance(r, Dataset | None) for r in obj ): raise TypeError( - f"the result of calling func on the node at position is not a Dataset or None " - f"or a tuple of such types: {obj!r}" + f"the result of calling func on the node at position '{path_to_node}' is" + f" not a Dataset or None or a tuple of such types:\n{obj!r}" ) return len(obj) diff --git a/xarray/tests/test_datatree_mapping.py b/xarray/tests/test_datatree_mapping.py index ec91a3c03e6..810804e06c7 100644 --- a/xarray/tests/test_datatree_mapping.py +++ b/xarray/tests/test_datatree_mapping.py @@ -72,7 +72,7 @@ def test_return_wrong_type(self, simple_datatree): with pytest.raises( TypeError, match=re.escape( - "the result of calling func on the node at position is not a " + "the result of calling func on the node at position '.' is not a " "Dataset or None or a tuple of such types" ), ): @@ -84,7 +84,7 @@ def test_return_tuple_of_wrong_types(self, simple_datatree): with pytest.raises( TypeError, match=re.escape( - "the result of calling func on the node at position is not a " + "the result of calling func on the node at position '.' is not a " "Dataset or None or a tuple of such types" ), ):