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

Commit d9c85b3

Browse files
authored
Add parent info to repr (#59)
* think I've fixed the bug * used feature from python 3.9 * test but doesn't yet work properly * only check subtree, not down to root * add parent info to repr * trigger CI
1 parent 6ae66b0 commit d9c85b3

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

datatree/datatree.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ def __str__(self):
223223
else:
224224
lines.append(f"{fill}{line}")
225225

226+
# Tack on info about whether or not root node has a parent at the start
227+
first_line = lines[0]
228+
parent = f'"{self.parent.name}"' if self.parent is not None else "None"
229+
first_line_with_parent = first_line[:-1] + f", parent={parent})"
230+
lines[0] = first_line_with_parent
231+
226232
return "\n".join(lines)
227233

228234
def _single_node_repr(self):
@@ -433,6 +439,8 @@ def isomorphic(
433439
from_root : bool, optional, default is False
434440
Whether or not to first traverse to the root of the trees before checking for isomorphism.
435441
If a & b have no parents then this has no effect.
442+
strict_names : bool, optional, default is False
443+
Whether or not to also check that each node has the same name as its counterpart.
436444
437445
See Also
438446
--------

datatree/tests/test_datatree.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,14 @@ class TestRepr:
291291
def test_print_empty_node(self):
292292
dt = DataTree("root")
293293
printout = dt.__str__()
294-
assert printout == "DataTree('root')"
294+
assert printout == "DataTree('root', parent=None)"
295295

296296
def test_print_node_with_data(self):
297297
dat = xr.Dataset({"a": [0, 2]})
298298
dt = DataTree("root", data=dat)
299299
printout = dt.__str__()
300300
expected = [
301-
"DataTree('root')",
301+
"DataTree('root', parent=None)",
302302
"Dimensions",
303303
"Coordinates",
304304
"a",

0 commit comments

Comments
 (0)