Skip to content

Commit ab26245

Browse files
committed
Improve error message
1 parent adcd0ac commit ab26245

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

xarray/core/combine.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,10 @@ def _dataarray_concat(arrays, dim, data_vars, coords, compat,
327327
name = result_name(arrays)
328328
names = [arr.name for arr in arrays]
329329
if compat == 'identical' and len(set(names)) != 1:
330-
raise ValueError('array names not identical')
330+
raise ValueError(
331+
"compat='identical', but array names {!r} are not identical"
332+
.format(names if len(names) <= 10 else sorted(set(names)))
333+
)
331334
datasets = [arr.rename(name)._to_temp_dataset() for arr in arrays]
332335

333336
if isinstance(dim, str) and len(set(names) - {None}) == len(names) \

xarray/tests/test_combine.py

+5
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@ def test_concat_names_and_coords(self):
306306
new = concat([ds.foo, ds.bar], dim='new')
307307
assert new.name is None
308308
assert (new.coords['new'] == ['foo', 'bar']).values.all()
309+
# Get a useful error message for unexpectedly different names
310+
with pytest.raises(ValueError) as err:
311+
concat([ds.foo, ds.bar], dim='new', compat='identical')
312+
assert err.value.args[0] == "compat='identical', " + \
313+
"but array names '['foo', 'bar'] are not identical"
309314
# Concat arrays with same name, name is preserved
310315
# and non-unique names are not used as coords
311316
foobar = ds.foo.rename('bar')

0 commit comments

Comments
 (0)