|
1 | 1 | import json
|
2 | 2 | from collections.abc import Iterator
|
3 |
| -from typing import Any |
| 3 | +from typing import Any, Literal |
4 | 4 |
|
5 | 5 | import numcodecs.vlen
|
6 | 6 | import numpy as np
|
@@ -126,9 +126,54 @@ async def test_create_dtype_str(dtype: Any) -> None:
|
126 | 126 |
|
127 | 127 |
|
128 | 128 | @pytest.mark.parametrize("filters", [[], [numcodecs.Delta(dtype="<i4")], [numcodecs.Zlib(level=2)]])
|
129 |
| -def test_v2_filters_codecs(filters: Any) -> None: |
| 129 | +@pytest.mark.parametrize("order", ["C", "F"]) |
| 130 | +def test_v2_filters_codecs(filters: Any, order: Literal["C", "F"]) -> None: |
130 | 131 | array_fixture = [42]
|
131 |
| - arr = zarr.create(shape=1, dtype="<i4", zarr_format=2, filters=filters) |
| 132 | + arr = zarr.create(shape=1, dtype="<i4", zarr_format=2, filters=filters, order=order) |
132 | 133 | arr[:] = array_fixture
|
133 | 134 | result = arr[:]
|
134 | 135 | np.testing.assert_array_equal(result, array_fixture)
|
| 136 | + |
| 137 | + |
| 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: |
| 141 | + arr = zarr.Array.create( |
| 142 | + MemoryStore({}), |
| 143 | + shape=(10, 8), |
| 144 | + chunks=(3, 3), |
| 145 | + fill_value=np.nan, |
| 146 | + dtype="float64", |
| 147 | + zarr_format=2, |
| 148 | + exists_ok=True, |
| 149 | + order=array_order, |
| 150 | + ) |
| 151 | + |
| 152 | + # Non-contiguous write |
| 153 | + a = np.arange(arr.shape[0] * arr.shape[1]).reshape(arr.shape, order=data_order) |
| 154 | + arr[slice(6, 9, None), slice(3, 6, None)] = a[ |
| 155 | + slice(6, 9, None), slice(3, 6, None) |
| 156 | + ] # The slice on the RHS is important |
| 157 | + np.testing.assert_array_equal( |
| 158 | + arr[slice(6, 9, None), slice(3, 6, None)], a[slice(6, 9, None), slice(3, 6, None)] |
| 159 | + ) |
| 160 | + |
| 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 | + ) |
| 171 | + |
| 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 |
| 178 | + arr[slice(6, 9, None), slice(3, 6, None)] = a |
| 179 | + np.testing.assert_array_equal(arr[slice(6, 9, None), slice(3, 6, None)], a) |
0 commit comments