pydata / pydata/xarray

Ability to index a DataTree with a PurePosixPath

Open
#9,253 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Is your feature request related to a problem?

When working with DataTrees, that are tree-like structure, it is common to have to build paths to access the data contained inside of it. It is then natural to envision pathlib as an help to build such paths, rather than relying on strings. DataTree already uses its NodePath structure internally, that inherit from PurePosixPath

On can already do this:

path = PurePosixPath("/a/b/c/")
xdt: DataTree
xdt[str(path)]

But having to add this str call adds noise to the code.

Describe the solution you'd like
xdt: DataTree
xdt[PurePosixPath("/a/b") / "c"]
Describe alternatives you've considered

Calling str to an existing PurePosixPath is the most natural way: use pathlib to build a path and downgrade to a string accepter by the DataTree indexing logic

Additional context

No response

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

The issue names the DataTree indexing entry point but no files or tests. Start by locating the DataTree indexing logic and its NodePath handling, then run the relevant indexing tests. Done means a PurePosixPath can be used directly for the shown lookup without changing existing string-path behavior.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.