From b4f5a734fb01167fe6d654f1ebb6482c005ba7ed Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 23 Sep 2025 10:08:27 +0100 Subject: [PATCH] Include shard/chunk shapes in size mismatch error --- src/zarr/codecs/sharding.py | 3 ++- tests/test_codecs/test_sharding.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/zarr/codecs/sharding.py b/src/zarr/codecs/sharding.py index ecbd258ccf..b0fd75cef7 100644 --- a/src/zarr/codecs/sharding.py +++ b/src/zarr/codecs/sharding.py @@ -431,7 +431,8 @@ def validate( ) ): raise ValueError( - "The array's `chunk_shape` needs to be divisible by the shard's inner `chunk_shape`." + f"The array's `chunk_shape` (got {chunk_grid.chunk_shape}) " + f"needs to be divisible by the shard's inner `chunk_shape` (got {self.chunk_shape})." ) async def _decode_single( diff --git a/tests/test_codecs/test_sharding.py b/tests/test_codecs/test_sharding.py index eb80545ff3..7eb4deccbf 100644 --- a/tests/test_codecs/test_sharding.py +++ b/tests/test_codecs/test_sharding.py @@ -1,4 +1,5 @@ import pickle +import re from typing import Any import numpy as np @@ -486,3 +487,20 @@ def test_invalid_metadata(store: Store) -> None: dtype=np.dtype("uint8"), fill_value=0, ) + + +def test_invalid_shard_shape() -> None: + with pytest.raises( + ValueError, + match=re.escape( + "The array's `chunk_shape` (got (16, 16)) needs to be divisible by the shard's inner `chunk_shape` (got (9,))." + ), + ): + zarr.create_array( + {}, + shape=(16, 16), + shards=(16, 16), + chunks=(9,), + dtype=np.dtype("uint8"), + fill_value=0, + )