Skip to content

Commit c0a75b5

Browse files
committed
add developers note on class structure of DataTree
1 parent 631aabf commit c0a75b5

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

datatree/datatree.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@
3636
| |-- DataNode("elevation")
3737
| | Variable("height_above_sea_level")
3838
|-- DataNode("population")
39+
40+
41+
DEVELOPERS' NOTE
42+
----------------
43+
The idea of this module is to create a `DataTree` class which inherits the tree structure from TreeNode, and also copies
44+
the entire API of `xarray.Dataset`, but with certain methods decorated to instead map the dataset function over every
45+
node in the tree. As this API is copied without directly subclassing `xarray.Dataset` we instead create various Mixin
46+
classes which each define part of `xarray.Dataset`'s extensive API.
47+
3948
"""
4049

4150

@@ -227,8 +236,7 @@ def imag(self):
227236
'isin', 'astype']
228237

229238
# TODO NUM_BINARY_OPS apparently aren't defined on DatasetArithmetic, and don't appear to be injected anywhere...
230-
#['__array_ufunc__'] \
231-
_ARITHMETIC_METHODS_TO_WRAP = REDUCE_METHODS + NAN_REDUCE_METHODS + NAN_CUM_METHODS
239+
_ARITHMETIC_METHODS_TO_MAP = REDUCE_METHODS + NAN_REDUCE_METHODS + NAN_CUM_METHODS + ['__array_ufunc__']
232240

233241

234242
def _wrap_then_attach_to_cls(target_cls_dict, source_cls, methods_to_set, wrap_func=None):
@@ -296,7 +304,7 @@ class DataTreeArithmetic(DatasetArithmetic):
296304
because they (a) only call dataset properties and (b) don't return a dataset that should be nested into a new
297305
tree) and some will get overridden by the class definition of DataTree.
298306
"""
299-
_wrap_then_attach_to_cls(vars(), DatasetArithmetic, _ARITHMETIC_METHODS_TO_WRAP, wrap_func=map_over_subtree)
307+
_wrap_then_attach_to_cls(vars(), DatasetArithmetic, _ARITHMETIC_METHODS_TO_MAP, wrap_func=map_over_subtree)
300308

301309

302310
class DataTree(TreeNode, DatasetPropertiesMixin, MappedDatasetMethodsMixin, MappedDataWithCoords, DataTreeArithmetic):
@@ -343,6 +351,8 @@ class DataTree(TreeNode, DatasetPropertiesMixin, MappedDatasetMethodsMixin, Mapp
343351

344352
# TODO dataset methods which should not or cannot act over the whole tree, such as .to_array
345353

354+
# TODO del and delitem methods
355+
346356
def __init__(
347357
self,
348358
data_objects: Dict[PathType, Union[Dataset, DataArray]] = None,

0 commit comments

Comments
 (0)