pydata / pydata/xarray

DataTree.__contains__ should support pathlike syntax

Open
#9,354 0 comments 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?

Summarizing https://github.com/xarray-contrib/datatree/issues/240#issue-1671753316:

Basically DataTree.__getitem__ will currently return more things than DataTree.__contains__ will actually tell you are "in" the tree, which can be confusing.

To fix this __contains__ should support path-like syntax.

I also think that it's convenient that we can separate the "is this key in the local node's variables" question from the "is this path in the tree anywhere" question. In the former case the key will never have a / character and the latter case it will always have one, so we could perhaps think of this like overloading the __contains__ method to behave slightly differently for str vs PathLike types.

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 with the DataTree.contains and DataTree.getitem entry points, then inspect existing DataTree membership tests. Confirm the expected distinction between local-node variable keys and path-like tree membership, and consider the work done when membership behavior is consistent with lookup behavior for the described inputs.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.