Allow data variables paths instead of just names in xarray.concat when passing DataTrees
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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