From 6f7602f6e37785ca54be0751e41d6f86531e7d6e Mon Sep 17 00:00:00 2001 From: Zac Hatfield-Dodds Date: Thu, 21 Feb 2019 09:48:10 +1100 Subject: [PATCH] Improve error message --- xarray/core/combine.py | 5 ++++- xarray/tests/test_combine.py | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/xarray/core/combine.py b/xarray/core/combine.py index fae9d85fac8..c4b20bdb54c 100644 --- a/xarray/core/combine.py +++ b/xarray/core/combine.py @@ -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) \ diff --git a/xarray/tests/test_combine.py b/xarray/tests/test_combine.py index 8487d305af0..c5e88e1f627 100644 --- a/xarray/tests/test_combine.py +++ b/xarray/tests/test_combine.py @@ -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')