Skip to content

Commit

Permalink
Set coord name concat when concating along a DataArray (#5611)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcaria authored Aug 23, 2021
1 parent 059c91a commit 808b2e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions xarray/core/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ def _calc_concat_dim_coord(dim):
(dim,) = coord.dims
else:
coord = dim
if coord.name is None:
coord.name = dim.dims[0]
(dim,) = coord.dims
return dim, coord

Expand Down
9 changes: 9 additions & 0 deletions xarray/tests/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,15 @@ def test_concat_str_dtype(self, dtype, dim):

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

def test_concat_coord_name(self):

da = DataArray([0], dims="a")
da_concat = concat([da, da], dim=DataArray([0, 1], dims="b"))
assert list(da_concat.coords) == ["b"]

da_concat_std = concat([da, da], dim=DataArray([0, 1]))
assert list(da_concat_std.coords) == ["dim_0"]


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

0 comments on commit 808b2e9

Please sign in to comment.