Skip to content

Commit 5375e07

Browse files
Child dict refactor (also removes anytree dependency) xarray-contrib/datatree#76
* draft implementation of a TreeNode class which stores children in a dict * separate path-like access out into mixin * pseudocode for node getter * basic idea for a path-like object which inherits from pathlib * pass type checking * implement attach * consolidate tree classes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * passes some basic family tree tests * frozen children * passes all basic family tree tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * copied iterators code over from anytree * get nodes with path-like syntax * relative path method * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * set and get node methods * copy anytree iterators * add anytree license * change iterator import * copy anytree's string renderer * renderer * refactored treenode to use .get * black * updated datatree tests to match new path API * moved io tests to their own file * reimplemented getitem in terms of .get * reimplemented setitem in terms of .update * remove anytree dependency * from_dict constructor * string representation of tree * fixed tree diff * fixed io * removed cheeky print statements * fixed isomorphism checking * fixed map_over_subtree * removed now-uneeded utils.py compatibility functions * fixed tests for mapped dataset api methods * updated API docs * reimplement __setitem__ in terms of _set * fixed bug by ensuring name of child node is changed to match key it is stored under * updated docs * added whats-new, and put all changes from this PR in it * added summary of previous versions * remove outdated ._add_child method Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 907447d commit 5375e07

24 files changed

+1987
-973
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ This aims to create the data structure discussed in [xarray issue #4118](https:/
55

66

77
The approach used here is based on benbovy's [`DatasetNode` example](https://gist.github.com/benbovy/92e7c76220af1aaa4b3a0b65374e233a) - the basic idea is that each tree node wraps a up to a single `xarray.Dataset`. The differences are that this effort:
8-
- [Uses a NodeMixin from anytree](https://github.com/TomNicholas/datatree/issues/7) for the tree structure,
9-
- Implements path-like and tag-like getting and setting,
8+
- Uses a node structure inspired by [anytree](https://github.com/TomNicholas/datatree/issues/7) for the tree,
9+
- Implements path-like getting and setting,
1010
- Has functions for mapping user-supplied functions over every node in the tree,
1111
- Automatically dispatches *some* of `xarray.Dataset`'s API over every node in the tree (such as `.isel`),
1212
- Has a bunch of tests,
@@ -17,5 +17,5 @@ You can create a `DataTree` object in 3 ways:
1717
1) Load from a netCDF file (or Zarr store) that has groups via `open_datatree()`.
1818
2) Using the init method of `DataTree`, which creates an individual node.
1919
You can then specify the nodes' relationships to one other, either by setting `.parent` and `.chlldren` attributes,
20-
or through `__get/setitem__` access, e.g. `dt['path/to/node'] = xr.Dataset()`.
20+
or through `__get/setitem__` access, e.g. `dt['path/to/node'] = DataTree()`.
2121
3) Create a tree from a dictionary of paths to datasets using `DataTree.from_dict()`.

ci/doc.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ dependencies:
66
- python>=3.8
77
- xarray>=0.20.2
88
- netcdf4
9-
- anytree
109
- scipy
1110
- sphinx
1211
- sphinx-copybutton

ci/environment.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ dependencies:
66
- python>=3.8
77
- xarray>=0.20.2
88
- netcdf4
9-
- anytree
109
- pytest
1110
- flake8
1211
- black

0 commit comments

Comments
 (0)