Skip to content

Commit

Permalink
List coordinates in concat error message, update test
Browse files Browse the repository at this point in the history
  • Loading branch information
mgunyho committed Aug 19, 2023
1 parent b7b2488 commit 26cb28e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 8 additions & 5 deletions xarray/core/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,20 @@ def process_subset_opt(opt, subset):
else:
raise ValueError(f"unexpected value for {subset}: {opt}")
else:
invalid_vars = [k for k in opt if k not in getattr(datasets[0], subset)]
valid_vars = tuple(getattr(datasets[0], subset))
invalid_vars = [k for k in opt if k not in valid_vars]
if invalid_vars:
if subset == "coords":
raise ValueError(
"some variables in coords are not coordinates on "
f"the first dataset: {invalid_vars}"
f"the variables {invalid_vars} in coords are not "
f"found in the coordinates of the first dataset {valid_vars}"
)
else:
# note: data_vars are not listed in the error message here,
# because there may be lots of them
raise ValueError(
"some variables in data_vars are not data variables "
f"on the first dataset: {invalid_vars}"
f"the variables {invalid_vars} in data_vars are not "
f"found in the data variables of the first dataset"
)
concat_over.update(opt)

Expand Down
5 changes: 4 additions & 1 deletion xarray/tests/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,12 @@ def test_concat_errors(self):
with pytest.raises(ValueError, match=r"must supply at least one"):
concat([], "dim1")

with pytest.raises(ValueError, match=r"are not coordinates"):
with pytest.raises(ValueError, match=r"are not found in the coordinates"):
concat([data, data], "new_dim", coords=["not_found"])

with pytest.raises(ValueError, match=r"are not found in the data variables"):
concat([data, data], "new_dim", data_vars=["not_found"])

with pytest.raises(ValueError, match=r"global attributes not"):
# call deepcopy seperately to get unique attrs
data0 = deepcopy(split_data[0])
Expand Down

0 comments on commit 26cb28e

Please sign in to comment.