Skip to content

Commit 2abd3d2

Browse files
committed
tests for failing read with sharding
1 parent 1131253 commit 2abd3d2

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

tests/v3/test_codecs/test_codecs.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,26 @@ def test_morton() -> None:
205205
]
206206

207207

208+
@pytest.mark.parametrize(
209+
"shape",
210+
[
211+
[2, 2, 2],
212+
[5, 2],
213+
[2, 5],
214+
[2, 2, 2, 2],
215+
[1, 2, 0],
216+
[2, 5, 1],
217+
[4, 3, 6, 2, 7],
218+
[3, 2, 1, 6, 4, 5, 2],
219+
],
220+
)
221+
def test_morton2(shape) -> None:
222+
order = list(morton_order_iter(shape))
223+
for i, x in enumerate(order):
224+
assert x not in order[:i] # no duplicates
225+
assert all(x[j] < shape[j] for j in range(len(shape))) # all indices are within bounds
226+
227+
208228
@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"])
209229
def test_write_partial_chunks(store: Store) -> None:
210230
data = np.arange(0, 256, dtype="uint16").reshape((16, 16))

tests/v3/test_codecs/test_sharding.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
ShardingCodec,
1414
ShardingCodecIndexLocation,
1515
TransposeCodec,
16+
Crc32cCodec,
1617
)
1718
from zarr.core.buffer import default_buffer_prototype
1819
from zarr.storage.common import StorePath
@@ -330,3 +331,27 @@ async def test_delete_empty_shards(store: Store) -> None:
330331
def test_pickle() -> None:
331332
codec = ShardingCodec(chunk_shape=(8, 8))
332333
assert pickle.loads(pickle.dumps(codec)) == codec
334+
335+
336+
@pytest.mark.parametrize("store", ("local", "memory"), indirect=["store"])
337+
@pytest.mark.parametrize(
338+
"index_location", [ShardingCodecIndexLocation.start, ShardingCodecIndexLocation.end]
339+
)
340+
async def test_sharding_2(store: Store, index_location: ShardingCodecIndexLocation) -> None:
341+
shape = (10, 2)
342+
data = np.ones(np.prod(shape), dtype="int32").reshape(shape)
343+
fill_value = 42
344+
345+
path = f"test_sharding_2{index_location}"
346+
spath = StorePath(store, path)
347+
a = Array.create(
348+
spath,
349+
shape=shape,
350+
chunk_shape=shape,
351+
dtype="int32",
352+
fill_value=fill_value,
353+
codecs=[ShardingCodec(chunk_shape=(2, 1), index_location=index_location)],
354+
)
355+
a[...] = data
356+
data_read = a[...]
357+
assert np.array_equal(data_read, data)

0 commit comments

Comments
 (0)