Skip to content

Commit

Permalink
Improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Feb 20, 2019
1 parent adcd0ac commit ab26245
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion xarray/core/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,10 @@ def _dataarray_concat(arrays, dim, data_vars, coords, compat,
name = result_name(arrays)
names = [arr.name for arr in arrays]
if compat == 'identical' and len(set(names)) != 1:
raise ValueError('array names not identical')
raise ValueError(
"compat='identical', but array names {!r} are not identical"
.format(names if len(names) <= 10 else sorted(set(names)))
)
datasets = [arr.rename(name)._to_temp_dataset() for arr in arrays]

if isinstance(dim, str) and len(set(names) - {None}) == len(names) \
Expand Down
5 changes: 5 additions & 0 deletions xarray/tests/test_combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ def test_concat_names_and_coords(self):
new = concat([ds.foo, ds.bar], dim='new')
assert new.name is None
assert (new.coords['new'] == ['foo', 'bar']).values.all()
# Get a useful error message for unexpectedly different names
with pytest.raises(ValueError) as err:
concat([ds.foo, ds.bar], dim='new', compat='identical')
assert err.value.args[0] == "compat='identical', " + \
"but array names '['foo', 'bar'] are not identical"
# Concat arrays with same name, name is preserved
# and non-unique names are not used as coords
foobar = ds.foo.rename('bar')
Expand Down

0 comments on commit ab26245

Please sign in to comment.