Repository: pydata/xarray

Issue:
Coord name not set when `concat`ing along a DataArray
```python
from xarray import DataArray, concat
a = DataArray([0], dims='a')
out = concat([a, a], dim=DataArray([0, 1], dims='b'))
print(out.coords)
```

> Coordinates:
> >   None     (b) int32 0 1


I would've expected the name of the new coordinate to be the name of the DataArray variable but instead it's `None`.

**Environment**:

<details><summary>Output of <tt>xr.show_versions()</tt></summary>

INSTALLED VERSIONS
------------------
commit: None
python: 3.9.2 | packaged by conda-forge | (default, Feb 21 2021, 04:59:43) [MSC v.1916 64 bit (AMD64)]
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: English_United States.1252
libhdf5: None
libnetcdf: None

xarray: 0.17.0
pandas: 1.2.4
numpy: 1.20.2
scipy: None
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: None
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
pint: None
setuptools: 49.6.0.post20210108
pip: 21.1.1
conda: None
pytest: None
IPython: 7.23.0
sphinx: None


</details>


Discussion:
github-actions[bot]: ## Unit Test Results
         6 files           6 suites   57m 29s :stopwatch:
16 173 tests 14 451 :heavy_check_mark: 1 721 :zzz: 1 :x:
90 234 runs  82 086 :heavy_check_mark: 8 142 :zzz: 6 :x:

For more details on these failures, see [this check](https://github.com/pydata/xarray/runs/3079352782).

Results for commit cc0d378b.

max-sixty: Sorry this got missed @gcaria — it looks good. Let's merge in the next couple of days if unless anyone has any thoughts.

Would it be possible to merge main into this so the tests pass?
gcaria: No worries @max-sixty, rebased to main and all tests work fine now!

Patch:
diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs
new file mode 100644
index 00000000..465572c9
--- /dev/null
+++ b/.git-blame-ignore-revs
@@ -0,0 +1,5 @@
+# black PR 3142
+d089df385e737f71067309ff7abae15994d581ec
+
+# isort PR 1924
+0e73e240107caee3ffd1a1149f0150c390d43251
diff --git a/xarray/core/concat.py b/xarray/core/concat.py
index 7a15685f..e26c1464 100644
--- a/xarray/core/concat.py
+++ b/xarray/core/concat.py
@@ -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
 


Test patch:
diff --git a/xarray/tests/test_concat.py b/xarray/tests/test_concat.py
index 36ef0237..e049f843 100644
--- a/xarray/tests/test_concat.py
+++ b/xarray/tests/test_concat.py
@@ -678,6 +678,15 @@ class TestConcatDataArray:
 
         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]}, {}))