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
Changes from 1 commit
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
18 changes: 4 additions & 14 deletions 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 Expand Up @@ -1163,16 +1166,3 @@ def test_combine_by_coords_raises_for_differing_types():
TypeError, match=r"Cannot combine along dimension 'time' with mixed types."
):
combine_by_coords([da_1, da_2])


def test_combine_by_coords_raises_for_no_index():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW this was a nice test because it included the coord name! But no great stress

# previously failed with uninformative ValueError

da1 = DataArray([1, 2, 3], dims="x", coords={"x": [1, 2, 3]})
da2 = DataArray([1, 2, 3], dims="x", coords={"x": [4, 5, 6]})
da1 = da1.drop_indexes("x")
with pytest.raises(
ValueError,
match=r"Every dimension requires a corresponding 1D coordinate and index for inferring concatenation order but the coordinate 'x' has no corresponding index",
):
combine_by_coords([da1, da2])
Loading