|
5 | 5 | import numpy as np |
6 | 6 | import pytest |
7 | 7 |
|
8 | | -from src.zarr.core.array import chunks_initialized |
9 | 8 | from zarr import Array, AsyncArray, Group |
| 9 | +from zarr.core.array import chunks_initialized |
10 | 10 | from zarr.core.buffer.cpu import NDBuffer |
11 | 11 | from zarr.core.common import ZarrFormat |
| 12 | +from zarr.core.indexing import ceildiv |
12 | 13 | from zarr.core.sync import sync |
13 | 14 | from zarr.errors import ContainsArrayError, ContainsGroupError |
14 | 15 | from zarr.store import LocalStore, MemoryStore |
@@ -237,6 +238,23 @@ def test_serializable_sync_array(store: LocalStore, zarr_format: ZarrFormat) -> |
237 | 238 | np.testing.assert_array_equal(actual[:], expected[:]) |
238 | 239 |
|
239 | 240 |
|
| 241 | +@pytest.mark.parametrize("test_cls", [Array, AsyncArray]) |
| 242 | +@pytest.mark.parametrize("nchunks", (2, 5, 10)) |
| 243 | +def test_nchunks(test_cls: type[Array] | type[AsyncArray], nchunks: int) -> None: |
| 244 | + """ |
| 245 | + Test that nchunks returns the number of chunks defined for the array. |
| 246 | + """ |
| 247 | + store = MemoryStore({}, mode="w") |
| 248 | + shape = 100 |
| 249 | + arr = Array.create(store, shape=(shape,), chunks=(ceildiv(shape, nchunks),), dtype="i4") |
| 250 | + expected = nchunks |
| 251 | + if test_cls == Array: |
| 252 | + observed = arr.nchunks |
| 253 | + else: |
| 254 | + observed = arr._async_array.nchunks |
| 255 | + assert observed == expected |
| 256 | + |
| 257 | + |
240 | 258 | @pytest.mark.parametrize("test_cls", [Array, AsyncArray]) |
241 | 259 | def test_nchunks_initialized(test_cls: type[Array] | type[AsyncArray]) -> None: |
242 | 260 | """ |
|
0 commit comments