Skip to content

Commit 03648fb

Browse files
committed
Handle array names in concat
e.g. where some names may be None, or where there may be collisions with existing coordinates.
1 parent 51bdeb7 commit 03648fb

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

xarray/core/combine.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -325,16 +325,16 @@ def _dataarray_concat(arrays, dim, data_vars, coords, compat,
325325
'concatenating DataArray objects')
326326

327327
name = result_name(arrays)
328-
if name is None and compat == 'identical':
328+
names = [arr.name for arr in arrays]
329+
if compat == 'identical' and len(set(names)) != 1:
329330
raise ValueError('array names not identical')
330331
datasets = [arr.rename(name)._to_temp_dataset() for arr in arrays]
331332

332-
if name is None and isinstance(dim, str) and dim not in arrays[0].dims:
333-
# If we're concatenating uniquely named arrays along a new dimension,
334-
# use the existing names as coordinates.
335-
names = [arr.name for arr in arrays]
336-
if len(set(names) - {None}) == len(names):
337-
dim = pd.Index(names, name=dim)
333+
if isinstance(dim, str) and len(set(names) - {None}) == len(names) \
334+
and not any(dim in a.dims or dim in a.coords for a in arrays):
335+
# We're concatenating arrays with unique non-None names along
336+
# a new dimension, so we use the existing names as coordinates.
337+
dim = pd.Index(names, name=dim)
338338

339339
ds = _dataset_concat(datasets, dim, data_vars, coords, compat,
340340
positions)

0 commit comments

Comments
 (0)