datatree/datatree.py
def _get_item_from_path(self, path: PathType) -> Union[TreeNode, Dataset, DataArray]:
        """Get item given a path. Two valid cases: either all parts of path are nodes or last part is a variable."""

        # TODO this currently raises a ChildResolverError if it can't find a data variable in the ds - that's inconsistent with xarray.Dataset.__getitem__

        path = self._tuple_or_path_to_path(path)
        tags = [tag for tag in path.split(self.separator) if tag not in [self.separator, '']]
        *leading_tags, last_tag = tags

        if leading_tags is not None:
            penultimate = self.get_node(tuple(leading_tags))
        else:
            penultimate = self

        if penultimate.has_data and last_tag in penultimate.ds:
            return penultimate.ds[last_tag]
        else:
            return penultimate.get_node(last_tag)
Get item given a path. Two valid cases: either all parts of path are nodes or last part is a variable.
Get item given a path. Two valid cases: either all parts of path are nodes or last part is a variable.
Get item given a path . Two valid cases : either all parts of path are nodes or last part is a variable .
def _get_item_from_path(self, path: PathType) -> Union[TreeNode, Dataset, DataArray]:
        path = self._tuple_or_path_to_path(path)
        tags = [tag for tag in path.split(self.separator) if tag not in [self.separator, '']]
        *leading_tags, last_tag = tags
        if leading_tags is not None:
            penultimate = self.get_node(tuple(leading_tags))
        else:
            penultimate = self
        if penultimate.has_data and last_tag in penultimate.ds:
            return penultimate.ds[last_tag]
        else:
            return penultimate.get_node(last_tag)
def _get_item_from_path ( self , path : PathType ) -> Union [ TreeNode , Dataset , DataArray ] : path = self . _tuple_or_path_to_path ( path ) tags = [ tag for tag in path . split ( self . separator ) if tag not in [ self . separator , '' ] ] * leading_tags , last_tag = tags if leading_tags is not None : penultimate = self . get_node ( tuple ( leading_tags ) ) else : penultimate = self if penultimate . has_data and last_tag in penultimate . ds : return penultimate . ds [ last_tag ] else : return penultimate . get_node ( last_tag )
Get item given a path.
Get item given a path .
"""Get item given a path. Two valid cases: either all parts of path are nodes or last part is a variable.""" # TODO this currently raises a ChildResolverError if it can't find a data variable in the ds - that's inconsistent with xarray.Dataset.__getitem__
self
path
PathType