|
74 | 74 | ZarrUserWarning,
|
75 | 75 | )
|
76 | 76 | from zarr.storage import LocalStore, MemoryStore, StorePath
|
| 77 | +from zarr.storage._logging import LoggingStore |
77 | 78 |
|
78 | 79 | from .test_dtype.conftest import zdtype_examples
|
79 | 80 |
|
@@ -2119,3 +2120,28 @@ def test_iter_chunk_regions(
|
2119 | 2120 | assert observed == expected
|
2120 | 2121 | assert observed == tuple(arr._iter_chunk_regions())
|
2121 | 2122 | assert observed == tuple(arr._async_array._iter_chunk_regions())
|
| 2123 | + |
| 2124 | + |
| 2125 | +@pytest.mark.parametrize("num_shards", [1, 3]) |
| 2126 | +@pytest.mark.parametrize("array_type", ["numpy", "zarr"]) |
| 2127 | +def test_create_array_with_data_num_gets( |
| 2128 | + num_shards: int, array_type: Literal["numpy", "zarr"] |
| 2129 | +) -> None: |
| 2130 | + """ |
| 2131 | + Test that creating an array with data only invokes a single get request per stored object |
| 2132 | + """ |
| 2133 | + store = LoggingStore(store=MemoryStore()) |
| 2134 | + |
| 2135 | + chunk_shape = (1,) |
| 2136 | + shard_shape = (100,) |
| 2137 | + shape = (shard_shape[0] * num_shards,) |
| 2138 | + data: Array | npt.NDArray[np.int64] |
| 2139 | + if array_type == "numpy": |
| 2140 | + data = np.zeros(shape[0], dtype="int64") |
| 2141 | + else: |
| 2142 | + data = zarr.zeros(shape, dtype="int64") |
| 2143 | + |
| 2144 | + zarr.create_array(store, data=data, chunks=chunk_shape, shards=shard_shape, fill_value=-1) # type: ignore[arg-type] |
| 2145 | + # one get for the metadata and one per shard. |
| 2146 | + # Note: we don't actually need one get per shard, but this is the current behavior |
| 2147 | + assert store.counter["get"] == 1 + num_shards |
0 commit comments