Access child nodes, variables, or coordinates stored anywhere in this tree. Returned object will be either a DataTree or DataArray object depending on whether the key given points to a child or variable. Parameters ---------- key : str N
(self: DataTree, key: str)
| 979 | return default |
| 980 | |
| 981 | def __getitem__(self: DataTree, key: str) -> DataTree | DataArray: |
| 982 | """ |
| 983 | Access child nodes, variables, or coordinates stored anywhere in this tree. |
| 984 | |
| 985 | Returned object will be either a DataTree or DataArray object depending on whether the key given points to a |
| 986 | child or variable. |
| 987 | |
| 988 | Parameters |
| 989 | ---------- |
| 990 | key : str |
| 991 | Name of variable / child within this node, or unix-like path to variable / child within another node. |
| 992 | |
| 993 | Returns |
| 994 | ------- |
| 995 | DataTree | DataArray |
| 996 | """ |
| 997 | |
| 998 | # Either: |
| 999 | if utils.is_dict_like(key): |
| 1000 | # dict-like indexing |
| 1001 | raise NotImplementedError("Should this index over whole tree?") |
| 1002 | elif isinstance(key, str): |
| 1003 | # TODO should possibly deal with hashables in general? |
| 1004 | # path-like: a name of a node/variable, or path to a node/variable |
| 1005 | path = NodePath(key) |
| 1006 | return self._get_item(path) |
| 1007 | elif utils.is_list_like(key): |
| 1008 | # iterable of variable names |
| 1009 | raise NotImplementedError( |
| 1010 | "Selecting via tags is deprecated, and selecting multiple items should be " |
| 1011 | "implemented via .subset" |
| 1012 | ) |
| 1013 | else: |
| 1014 | raise ValueError(f"Invalid format for key: {key}") |
| 1015 | |
| 1016 | def _set(self, key: str, val: DataTree | CoercibleValue) -> None: |
| 1017 | """ |
no test coverage detected