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

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

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

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.

Description

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

Dominant language
Python
Stars
4.2k
Forks
1.5k
Avg merge
2d 21h
Merged PRs (30d)
74

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

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.

More from pydata/xarray

All issues in pydata/xarray

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.