pydata / pydata/xarray

Allow data variables paths instead of just names in xarray.concat when passing DataTrees

Open
#11,427 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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?

The current implementation of xarray.concat does not allow to specify paths of data variables that should be concatenated when operating on DataTrees. Instead, the data_vars argument is passed on to _dataset_concat calls unaltered on the individual nodes, so that passing a list of data variable names only works if those variables are present at all nodes of the trees.

Describe the solution you'd like

I would like to be able to specify a list of paths to data variables, e.g.

xr.concat((datatree_a, datatree_b), dim=xr.Variable("new_dim", ["a", "b"]), data_vars=["path/to/data_var_1", "path/to/data_var_2"])

The implementation of _datatree_concat would have to split the paths and then call _dataset_concat on each node only with the data vars prefixed with the path of each node.

Describe alternatives you've considered

No response

Additional context

Ideally, wildcards would be allowed both in the path and in the name of the data variable, this could easily be achieved using Pythons fnmatch module.

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 at _datatree_concat and trace how it passes data_vars to _dataset_concat for each node. Check the existing xarray.concat DataTree behavior and tests before implementing path splitting; done means paths select only the requested variables across the relevant nodes, while the wildcard behavior should be addressed only if its scope is clear.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.