diff --git a/xarray/core/combine.py b/xarray/core/combine.py index 6f652cb6597..4b4a07ddc77 100644 --- a/xarray/core/combine.py +++ b/xarray/core/combine.py @@ -89,10 +89,12 @@ def _infer_concat_order_from_coords(datasets): # Need to read coordinate values to do ordering indexes = [ds._indexes.get(dim) for ds in datasets] if any(index is None for index in indexes): - raise ValueError( - "Every dimension needs a coordinate for " - "inferring concatenation order" + error_msg = ( + f"Every dimension requires a corresponding 1D coordinate " + f"and index for inferring concatenation order but the " + f"coordinate '{dim}' has no corresponding index" ) + raise ValueError(error_msg) # TODO (benbovy, flexible indexes): support flexible indexes? indexes = [index.to_pandas_index() for index in indexes] diff --git a/xarray/tests/test_combine.py b/xarray/tests/test_combine.py index aad7103c112..1c48dca825d 100644 --- a/xarray/tests/test_combine.py +++ b/xarray/tests/test_combine.py @@ -728,7 +728,10 @@ def test_combine_by_coords(self): combine_by_coords(objs) objs = [Dataset({"x": [0], "y": [0]}), Dataset({"x": [0]})] - with pytest.raises(ValueError, match=r"Every dimension needs a coordinate"): + with pytest.raises( + ValueError, + match=r"Every dimension requires a corresponding 1D coordinate and index", + ): combine_by_coords(objs) def test_empty_input(self):