pydata / pydata/xarray

Indexing tree should create new tree

Open
#9,341 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

What is your issue?

Inspired by this example in the stackstac documentation

lowcloud = stack[stack["eo:cloud_cover"] < 20]

we should ensure that you can index a datatree with another (isomorphic) datatree, so that the above operation would work even if stack is a DataTree instance.

This is another map_over_subtree-type operation, but it needs careful testing because the __getitem__ function in xarray objects already does so many different things. This won't work with the code as-is because at the moment the DataTree naively dispatches the __getitem__ call down to the wrapped dataset.

https://github.com/xarray-contrib/datatree/blob/cd0695160e261466efc7f51fece02ca9bea2101c/datatree/datatree.py#L238

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

Start in datatree/datatree.py around the linked getitem implementation, then read the existing map_over_subtree pattern. Check how xarray object indexing is currently dispatched and identify the behavior needed for indexing one isomorphic DataTree with another. Done means the operation creates the expected new tree while preserving the existing getitem behaviors, with careful tests for the different indexing cases.

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
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.