Skip to content

Datatree does not inherit non-dimension coordinates #10812

@erooke

Description

@erooke

What is your issue?

When defining a data tree only dimension coordinates are inherited. For example

import numpy as np
import xarray as xr

N = 10


ds_1 = xr.Dataset(
    coords={
        "a": ("a", np.arange(N)),
        "a_meta": ("a", np.arange(N) * 3),
    }
)

ds_2 = xr.Dataset(data_vars={"data": ("a", np.arange(N) * 5)})

dt = xr.DataTree.from_dict(
    {
        "/": ds_1,
        "/data": ds_2,
    }
)

print(dt["/data"])

Results in:

<xarray.DataTree 'data'>
Group: /data
    Dimensions:  (a: 10)
    Inherited coordinates:
      * a        (a) int64 80B 0 1 2 3 4 5 6 7 8 9
    Data variables:
        data     (a) int64 80B 0 5 10 15 20 25 30 35 40 45

I could not find any mention in the docs that this is the expected behavior. The user guide does not make any sort of distinction and just refers to "coordinates", same with the data structures entry on inheritance.

I'm not sure if this is a bug or undocumented behavior but as a new user after reading the above docs I expected a_meta to be inherited.

System Info

  • python version: 3.13.5
  • xarray version: 2025.4.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions