Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Child dict refactor (also removes anytree dependency) (#76)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
TomNicholas and pre-commit-ci[bot] authored Apr 27, 2022
1 parent cd06951 commit f492787
Show file tree
Hide file tree
Showing 24 changed files with 1,987 additions and 973 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ This aims to create the data structure discussed in [xarray issue #4118](https:/


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:
- [Uses a NodeMixin from anytree](https://github.com/TomNicholas/datatree/issues/7) for the tree structure,
- Implements path-like and tag-like getting and setting,
- Uses a node structure inspired by [anytree](https://github.com/TomNicholas/datatree/issues/7) for the tree,
- Implements path-like getting and setting,
- Has functions for mapping user-supplied functions over every node in the tree,
- Automatically dispatches *some* of `xarray.Dataset`'s API over every node in the tree (such as `.isel`),
- Has a bunch of tests,
Expand All @@ -17,5 +17,5 @@ You can create a `DataTree` object in 3 ways:
1) Load from a netCDF file (or Zarr store) that has groups via `open_datatree()`.
2) Using the init method of `DataTree`, which creates an individual node.
You can then specify the nodes' relationships to one other, either by setting `.parent` and `.chlldren` attributes,
or through `__get/setitem__` access, e.g. `dt['path/to/node'] = xr.Dataset()`.
or through `__get/setitem__` access, e.g. `dt['path/to/node'] = DataTree()`.
3) Create a tree from a dictionary of paths to datasets using `DataTree.from_dict()`.
1 change: 0 additions & 1 deletion ci/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ dependencies:
- python>=3.8
- xarray>=0.20.2
- netcdf4
- anytree
- scipy
- sphinx
- sphinx-copybutton
Expand Down
1 change: 0 additions & 1 deletion ci/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ dependencies:
- python>=3.8
- xarray>=0.20.2
- netcdf4
- anytree
- pytest
- flake8
- black
Expand Down
Loading

0 comments on commit f492787

Please sign in to comment.