Skip to content

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

Description

@cpegel

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions