From 04ffa6c4ba7fec3ec1c11e0a0b6a51e0a9b15545 Mon Sep 17 00:00:00 2001 From: dcherian Date: Wed, 6 May 2020 13:36:15 -0600 Subject: [PATCH] Propagate attributes for index variables. --- xarray/core/parallel.py | 3 +++ xarray/tests/test_dask.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/xarray/core/parallel.py b/xarray/core/parallel.py index c2b09c119ad..7ae5c624ea2 100644 --- a/xarray/core/parallel.py +++ b/xarray/core/parallel.py @@ -541,6 +541,9 @@ def map_blocks( hlg.layers[gname_l] = layer result = Dataset(coords=indexes, attrs=template.attrs) + for index in result.indexes: + result[index].attrs = template[index].attrs + for name, gname_l in var_key_map.items(): dims = template[name].dims var_chunks = [] diff --git a/xarray/tests/test_dask.py b/xarray/tests/test_dask.py index 63234a5319e..ba51c034296 100644 --- a/xarray/tests/test_dask.py +++ b/xarray/tests/test_dask.py @@ -972,6 +972,7 @@ def make_da(): coords={"x": np.arange(10), "y": np.arange(100, 120)}, name="a", ).chunk({"x": 4, "y": 5}) + da.x.attrs["long_name"] = "x" da.attrs["test"] = "test" da.coords["c2"] = 0.5 da.coords["ndcoord"] = da.x * 2 @@ -995,6 +996,9 @@ def make_ds(): map_ds.attrs["test"] = "test" map_ds.coords["xx"] = map_ds["a"] * map_ds.y + map_ds.x.attrs["long_name"] = "x" + map_ds.y.attrs["long_name"] = "y" + return map_ds