From 7960b02000a9d0c34ce0c6388a105b42de0e09c9 Mon Sep 17 00:00:00 2001 From: Huite Bootsma Date: Tue, 13 Aug 2024 15:39:37 +0200 Subject: [PATCH] Scalar dx values are 0 dim numpy arrays too --- tests/test_regrid/test_regridder.py | 10 ++++++---- xugrid/regrid/structured.py | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/test_regrid/test_regridder.py b/tests/test_regrid/test_regridder.py index 515881eef..bd8c1046c 100644 --- a/tests/test_regrid/test_regridder.py +++ b/tests/test_regrid/test_regridder.py @@ -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) diff --git a/xugrid/regrid/structured.py b/xugrid/regrid/structured.py index c670810ae..8b14044f8 100644 --- a/xugrid/regrid/structured.py +++ b/xugrid/regrid/structured.py @@ -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