Support DataTree in Xarray's top level functions
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?
Sometimes you might want to map one of the xarray top-level functions (especially xr.concat or xr.merge) over DataTree objects.
Whilst this could potentially be done manually, we could also imagine generalizing top-level functions to handle this out of the box.
Describe the solution you'd like
For this to work
xr.concat([dt1, dt2], concat_dim='time')
returning a single DataTree, with xr.concat applied to sets of datasets in corresponding nodes.
Describe alternatives you've considered
We could instead not change xarray's top-level functions but still ensure that its relatively easy to achieve using map_over_subtree, i.e.
concat_datatrees = datatree.map_over_subtree(xr.concat)
dt_concatenated = concat_datatrees([dt1, dt2], dim='time')
This would still require generalizing map_over_subtree to understand iterables of DataTree objects though (see https://github.com/zarr-developers/VirtualiZarr/issues/84#issuecomment-2163789123).
Finally we could just not support this at all, in which case the only way for users to concatenate contents of datatrees node-wise is via something like
ds_concatenated = xr.concat([mytree[node].ds for subtree in mytree], dim="time")
but called for every node in the tree.
Additional context
See https://github.com/zarr-developers/VirtualiZarr/issues/84#issuecomment-2065410549 for an example of wanting to do this in VirtualiZarr (cc @jonas-spaeth).
This was actually already something we partly discussed in the datatree design meeting (https://github.com/pydata/xarray/issues/8747), but I forgot what the conclusion was (do you remember @keewis @flamingbear @owenlittlejohns?).
Checklist
-
apply_ufunc- https://github.com/pydata/xarray/issues/9789 -
concat- https://github.com/pydata/xarray/issues/9778 -
merge- https://github.com/pydata/xarray/issues/9790 -
align- https://github.com/pydata/xarray/issues/9791 -
broadcast -
combine_by_coords -
combine_nested- https://github.com/pydata/xarray/pull/10849 -
map_blocks
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
No files or tests are named. Start by reading the implementations of the top-level xr.concat and xr.merge functions and datatree.map_over_subtree, then review the linked DataTree design discussion. Done should be defined as consistent node-wise behavior for the listed top-level functions, with tests covering DataTree inputs and returned DataTree structure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100