Skip to content

Commit 808b2e9

Browse files
authored
Set coord name concat when concating along a DataArray (#5611)
1 parent 059c91a commit 808b2e9

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

xarray/core/concat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ def _calc_concat_dim_coord(dim):
264264
(dim,) = coord.dims
265265
else:
266266
coord = dim
267+
if coord.name is None:
268+
coord.name = dim.dims[0]
267269
(dim,) = coord.dims
268270
return dim, coord
269271

xarray/tests/test_concat.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,15 @@ def test_concat_str_dtype(self, dtype, dim):
678678

679679
assert np.issubdtype(actual.x2.dtype, dtype)
680680

681+
def test_concat_coord_name(self):
682+
683+
da = DataArray([0], dims="a")
684+
da_concat = concat([da, da], dim=DataArray([0, 1], dims="b"))
685+
assert list(da_concat.coords) == ["b"]
686+
687+
da_concat_std = concat([da, da], dim=DataArray([0, 1]))
688+
assert list(da_concat_std.coords) == ["dim_0"]
689+
681690

682691
@pytest.mark.parametrize("attr1", ({"a": {"meta": [10, 20, 30]}}, {"a": [1, 2, 3]}, {}))
683692
@pytest.mark.parametrize("attr2", ({"a": [1, 2, 3]}, {}))

0 commit comments

Comments
 (0)