pydata / pydata/xarray

DataTree.children repr is inconsistent with DataTree.parent (rich HTML vs. flat nested text)

Open
#11,453 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

What I expected

.parent and .children are symmetric tree-navigation operations — one step up, one step down. I expected them to render with parallel visual treatment.

What I got

They're rendered completely differently.

.parent returns a DataTree and gets the beautiful collapsible HTML repr:

>>> precipitation["reanalysis"].parent
<xarray.DataTree>
Group: /
├── Group: /observed
└── Group: /reanalysis
    ... (collapsible, indented, color-coded)

.children returns a Frozen mapping of name → DataTree, and each child's full repr is inlined as flat nested text:

>>> precipitation.children
Frozen({'observed': <xarray.DataTree 'observed'>
Group: /observed
    Dimensions:        (time: 10, lon: 320, lat: 150)
    Coordinates: ...
    Inherited coordinates: ...
    Data variables: ...
    ..., 'reanalysis': <xarray.DataTree 'reanalysis'>
Group: /reanalysis
    Dimensions: ...
    ...})

Two problems compound:

  1. Inconsistency. .parent (up) gives a structural view; .children (down) gives a flat dict. The asymmetry makes the API feel cobbled together.
  2. The tree shape is invisible at the exact moment you need it. .children is the operation that asks "what's below me?" — and the answer comes back as a wall of inline text with no hierarchy.

Why it matters

I was working through the DataTree tutorial at SciPy 2026, and the contrast jumped out immediately. The DataTree's HTML repr is excellent — it carries the whole "this is a hierarchy" mental model on its own. Then .children breaks that thread, dumping a verbose nested dict that obscures exactly the structure you're asking about.

For someone learning the API, the name .children promises a structural view. The repr delivers a wall of text.

Concrete proposal

My preferred direction is option 1, if maintainers are open to it:

  1. Preferred — reuse the existing DataTree HTML repr machinery. .children renders as a forest of mini-trees, each child shown with the same collapsible, indented treatment a standalone DataTree gets. Click-to-expand handles the verbosity, and the visual language matches .parent exactly. The repr code already exists; this is mostly a question of invoking it per-child and wrapping the results.

    Fallbacks if the full version is too much:

  2. Medium: A collapsible HTML view where each child expands into its full DataTree repr inline, collapsed by default. Less reuse of existing machinery, but still gives hierarchy + scannability.

  3. Minimum viable: An indented bulleted list of child names with a one-line summary each (path, dims, variable count). Skip the full per-child DataTree repr — that's what selecting the child is for. Easiest to land, closes most of the gap with .parent.

Environment

  • xarray version: 2026.7.0
  • Discovered while working through fundamentals/01_datatree_hierarchical_data.ipynb at SciPy 2026

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the contrast in fundamentals/01_datatree_hierarchical_data.ipynb, then trace the existing DataTree HTML repr machinery and the .children representation. Confirm the preferred rendering direction with maintainers; done means .children exposes its child hierarchy clearly without the current flat, verbose nested text.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.