Skip to content

Commit 57ac5cb

Browse files
committed
tests
1 parent a2fa097 commit 57ac5cb

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

tests/test_v2.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ def test_v2_filters_codecs(filters: Any, order: Literal["C", "F"]) -> None:
135135
np.testing.assert_array_equal(result, array_fixture)
136136

137137

138-
@pytest.mark.parametrize("order", ["C", "F"])
139-
def test_v2_non_contiguous(order: Literal["C", "F"]) -> None:
138+
@pytest.mark.parametrize("array_order", ["C", "F"])
139+
@pytest.mark.parametrize("data_order", ["C", "F"])
140+
def test_v2_non_contiguous(array_order: Literal["C", "F"], data_order: Literal["C", "F"]) -> None:
140141
arr = zarr.Array.create(
141142
MemoryStore({}),
142143
shape=(10, 8),
@@ -145,22 +146,34 @@ def test_v2_non_contiguous(order: Literal["C", "F"]) -> None:
145146
dtype="float64",
146147
zarr_format=2,
147148
exists_ok=True,
148-
order=order,
149+
order=array_order,
149150
)
150-
a = np.arange(arr.shape[0] * arr.shape[1]).reshape(arr.shape)
151+
152+
# Non-contiguous write
153+
a = np.arange(arr.shape[0] * arr.shape[1]).reshape(arr.shape, order=data_order)
151154
arr[slice(6, 9, None), slice(3, 6, None)] = a[
152155
slice(6, 9, None), slice(3, 6, None)
153156
] # The slice on the RHS is important
154157
np.testing.assert_array_equal(
155158
arr[slice(6, 9, None), slice(3, 6, None)], a[slice(6, 9, None), slice(3, 6, None)]
156159
)
157160

158-
a = np.arange(9).reshape((3, 3), order="F")
159-
assert a.flags.f_contiguous
160-
arr[slice(6, 9, None), slice(3, 6, None)] = a
161-
np.testing.assert_array_equal(arr[slice(6, 9, None), slice(3, 6, None)], a)
161+
arr = zarr.Array.create(
162+
MemoryStore({}),
163+
shape=(10, 8),
164+
chunks=(3, 3),
165+
fill_value=np.nan,
166+
dtype="float64",
167+
zarr_format=2,
168+
exists_ok=True,
169+
order=array_order,
170+
)
162171

163-
a = np.arange(9).reshape((3, 3), order="C")
164-
assert a.flags.c_contiguous
172+
# Contiguous write
173+
a = np.arange(9).reshape((3, 3), order=data_order)
174+
if data_order == "F":
175+
assert a.flags.f_contiguous
176+
else:
177+
assert a.flags.c_contiguous
165178
arr[slice(6, 9, None), slice(3, 6, None)] = a
166179
np.testing.assert_array_equal(arr[slice(6, 9, None), slice(3, 6, None)], a)

0 commit comments

Comments
 (0)