Skip to content

Commit

Permalink
Scalar dx values are 0 dim numpy arrays too
Browse files Browse the repository at this point in the history
  • Loading branch information
Huite committed Aug 13, 2024
1 parent d242307 commit 7960b02
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions tests/test_regrid/test_regridder.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,16 @@ def test_directional_dependence():
# orientation.
result = []
for source in [da, flipy, flipx, flipxy, uda, uda_flipxy]:
regridder = xu.OverlapRegridder(source, taget=target_da)
regridder = xu.OverlapRegridder(source, target=target_da)
result.append(regridder.regrid(source))
assert all(result[0] == item for item in result[1:])
first = result.pop(0)
assert all(first.identical(item) for item in result)

# Unstructured target: test whether the result is the same regardless of
# source orientation.
result = []
for source in [da, flipy, flipx, flipxy, uda, uda_flipxy]:
regridder = xu.OverlapRegridder(source, taget=target_uda)
regridder = xu.OverlapRegridder(source, target=target_uda)
result.append(regridder.regrid(source))
assert all(result[0] == item for item in result[1:])
first = result.pop(0)
assert all(first.identical(item) for item in result)
6 changes: 3 additions & 3 deletions xugrid/regrid/structured.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ def __init__(self, obj: Union[xr.DataArray, xr.Dataset], name: str):
@property
def coords(self) -> dict:
coords = {self.name: self.index}
if isinstance(self.dvalue, np.ndarray):
coords[self.dname] = (self.name, self.dvalue)
else:
if self.dvalue.ndim == 0:
coords[self.dname] = self.dvalue
else:
coords[self.dname] = (self.name, self.dvalue)
return coords

@property
Expand Down

0 comments on commit 7960b02

Please sign in to comment.