Skip to content

Commit a074a25

Browse files
committed
parametrize test over async
1 parent 02d661d commit a074a25

File tree

1 file changed

+38
-31
lines changed

1 file changed

+38
-31
lines changed

xarray/tests/test_variable.py

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2897,31 +2897,34 @@ def setUp(self):
28972897
self.d = np.random.random((10, 3)).astype(np.float64)
28982898
self.cat = PandasExtensionArray(pd.Categorical(["a", "b"] * 5))
28992899

2900-
async def check_orthogonal_indexing(self, v):
2900+
async def check_orthogonal_indexing(self, v, load_async):
29012901
expected = self.d[[8, 3]][:, [2, 1]]
29022902

2903-
result = v.isel(x=[8, 3], y=[2, 1])
2904-
assert np.allclose(result, expected)
2903+
if load_async:
2904+
result = await v.isel(x=[8, 3], y=[2, 1]).load_async()
2905+
else:
2906+
result = v.isel(x=[8, 3], y=[2, 1])
29052907

2906-
result = await v.isel(x=[8, 3], y=[2, 1]).load_async()
29072908
assert np.allclose(result, expected)
29082909

2909-
async def check_vectorized_indexing(self, v):
2910+
async def check_vectorized_indexing(self, v, load_async):
29102911
ind_x = Variable("z", [0, 2])
29112912
ind_y = Variable("z", [2, 1])
29122913
expected = self.d[ind_x, ind_y]
29132914

2914-
result = v.isel(x=ind_x, y=ind_y).load()
2915-
assert np.allclose(result, expected)
2915+
if load_async:
2916+
result = await v.isel(x=ind_x, y=ind_y).load_async()
2917+
else:
2918+
result = v.isel(x=ind_x, y=ind_y).load()
29162919

2917-
result = await v.isel(x=ind_x, y=ind_y).load_async()
29182920
assert np.allclose(result, expected)
29192921

29202922
@pytest.mark.asyncio
2921-
async def test_NumpyIndexingAdapter(self):
2923+
@pytest.mark.parametrize("load_async", [True, False])
2924+
async def test_NumpyIndexingAdapter(self, load_async):
29222925
v = Variable(dims=("x", "y"), data=NumpyIndexingAdapter(self.d))
2923-
await self.check_orthogonal_indexing(v)
2924-
await self.check_vectorized_indexing(v)
2926+
await self.check_orthogonal_indexing(v, load_async)
2927+
await self.check_vectorized_indexing(v, load_async)
29252928
# could not doubly wrapping
29262929
with pytest.raises(TypeError, match=r"NumpyIndexingAdapter only wraps "):
29272930
v = Variable(
@@ -2937,57 +2940,61 @@ def test_extension_array_duck_indexed(self):
29372940
assert (lazy[[0, 1, 5]] == ["a", "b", "b"]).all()
29382941

29392942
@pytest.mark.asyncio
2940-
async def test_LazilyIndexedArray(self):
2943+
@pytest.mark.parametrize("load_async", [True, False])
2944+
async def test_LazilyIndexedArray(self, load_async):
29412945
v = Variable(dims=("x", "y"), data=LazilyIndexedArray(self.d))
2942-
await self.check_orthogonal_indexing(v)
2943-
await self.check_vectorized_indexing(v)
2946+
await self.check_orthogonal_indexing(v, load_async)
2947+
await self.check_vectorized_indexing(v, load_async)
29442948
# doubly wrapping
29452949
v = Variable(
29462950
dims=("x", "y"),
29472951
data=LazilyIndexedArray(LazilyIndexedArray(self.d)),
29482952
)
2949-
await self.check_orthogonal_indexing(v)
2953+
await self.check_orthogonal_indexing(v, load_async)
29502954
# hierarchical wrapping
29512955
v = Variable(
29522956
dims=("x", "y"), data=LazilyIndexedArray(NumpyIndexingAdapter(self.d))
29532957
)
2954-
await self.check_orthogonal_indexing(v)
2958+
await self.check_orthogonal_indexing(v, load_async)
29552959

29562960
@pytest.mark.asyncio
2957-
async def test_CopyOnWriteArray(self):
2961+
@pytest.mark.parametrize("load_async", [True, False])
2962+
async def test_CopyOnWriteArray(self, load_async):
29582963
v = Variable(dims=("x", "y"), data=CopyOnWriteArray(self.d))
2959-
await self.check_orthogonal_indexing(v)
2960-
await self.check_vectorized_indexing(v)
2964+
await self.check_orthogonal_indexing(v, load_async)
2965+
await self.check_vectorized_indexing(v, load_async)
29612966
# doubly wrapping
29622967
v = Variable(dims=("x", "y"), data=CopyOnWriteArray(LazilyIndexedArray(self.d)))
2963-
await self.check_orthogonal_indexing(v)
2964-
await self.check_vectorized_indexing(v)
2968+
await self.check_orthogonal_indexing(v, load_async)
2969+
await self.check_vectorized_indexing(v, load_async)
29652970

29662971
@pytest.mark.asyncio
2967-
async def test_MemoryCachedArray(self):
2972+
@pytest.mark.parametrize("load_async", [True, False])
2973+
async def test_MemoryCachedArray(self, load_async):
29682974
v = Variable(dims=("x", "y"), data=MemoryCachedArray(self.d))
2969-
await self.check_orthogonal_indexing(v)
2970-
await self.check_vectorized_indexing(v)
2975+
await self.check_orthogonal_indexing(v, load_async)
2976+
await self.check_vectorized_indexing(v, load_async)
29712977
# doubly wrapping
29722978
v = Variable(dims=("x", "y"), data=CopyOnWriteArray(MemoryCachedArray(self.d)))
2973-
await self.check_orthogonal_indexing(v)
2974-
await self.check_vectorized_indexing(v)
2979+
await self.check_orthogonal_indexing(v, load_async)
2980+
await self.check_vectorized_indexing(v, load_async)
29752981

29762982
@requires_dask
29772983
@pytest.mark.asyncio
2978-
async def test_DaskIndexingAdapter(self):
2984+
@pytest.mark.parametrize("load_async", [True, False])
2985+
async def test_DaskIndexingAdapter(self, load_async):
29792986
import dask.array as da
29802987

29812988
dask_array = da.asarray(self.d)
29822989
v = Variable(dims=("x", "y"), data=DaskIndexingAdapter(dask_array))
2983-
await self.check_orthogonal_indexing(v)
2984-
await self.check_vectorized_indexing(v)
2990+
await self.check_orthogonal_indexing(v, load_async)
2991+
await self.check_vectorized_indexing(v, load_async)
29852992
# doubly wrapping
29862993
v = Variable(
29872994
dims=("x", "y"), data=CopyOnWriteArray(DaskIndexingAdapter(dask_array))
29882995
)
2989-
await self.check_orthogonal_indexing(v)
2990-
await self.check_vectorized_indexing(v)
2996+
await self.check_orthogonal_indexing(v, load_async)
2997+
await self.check_vectorized_indexing(v, load_async)
29912998

29922999

29933000
def test_clip(var):

0 commit comments

Comments
 (0)