Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message for missing coordinate index #9370

Merged
merged 3 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions xarray/core/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 4 additions & 1 deletion xarray/tests/test_combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading