Skip to content

Commit

Permalink
ignore missing coords on tmpl
Browse files Browse the repository at this point in the history
  • Loading branch information
aulemahal committed Sep 29, 2021
1 parent 6120e3d commit 3d52824
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion xclim/sdba/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,8 @@ def _call_and_transpose_on_exit(dsblock, **kwargs):
nam: crd for nam, crd in ds.coords.items() if nam not in crd.dims
}
ds = ds.drop_vars(extra_coords.keys())
tmpl = tmpl.drop_vars(extra_coords.keys())
# Coords not sharing dims with `all_dims` (like scalar aux coord on reduced 1D input) are absent from tmpl
tmpl = tmpl.drop_vars(extra_coords.keys(), errors="ignore")

# Call
out = ds.map_blocks(
Expand Down
13 changes: 9 additions & 4 deletions xclim/testing/tests/test_sdba/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def func(ds, *, group, lon=None):

data = func(
xr.Dataset(dict(tas=tas)), group="time.dayofyear", window=5, lon=[1, 2, 3, 4]
)
).load()
assert set(data.data.dims) == {"time", "lon"}

@map_groups(data=[Grouper.PROP])
Expand All @@ -185,7 +185,7 @@ def func(ds, *, dim):

data = func(
xr.Dataset(dict(tas=tas)), group="time.dayofyear", window=5, add_dims=["lat"]
)
).load()
assert set(data.data.dims) == {"dayofyear"}

@map_groups(data=[Grouper.PROP], main_only=True)
Expand All @@ -194,5 +194,10 @@ def func(ds, *, dim):
data = ds.tas.mean(dim)
return data.rename("data").to_dataset()

data = func(xr.Dataset(dict(tas=tas)), group="time.dayofyear")
assert set(data.data.dims) == {"dayofyear", "lat"}
# with a scalar aux coord
data = func(
xr.Dataset(dict(tas=tas.isel(lat=0, drop=True)), coords=dict(leftover=1)),
group="time.dayofyear",
).load()
assert set(data.data.dims) == {"dayofyear"}
assert "leftover" in data

0 comments on commit 3d52824

Please sign in to comment.