|
11 | 11 | import pytest |
12 | 12 |
|
13 | 13 | import zarr.api.asynchronous |
| 14 | +import zarr.api.synchronous as sync_api |
14 | 15 | from zarr import Array, AsyncArray, Group |
15 | 16 | from zarr.abc.store import Store |
16 | 17 | from zarr.codecs import ( |
|
38 | 39 | from zarr.core.common import JSON, MemoryOrder, ZarrFormat |
39 | 40 | from zarr.core.group import AsyncGroup |
40 | 41 | from zarr.core.indexing import BasicIndexer, ceildiv |
41 | | -from zarr.core.metadata.v3 import DataType |
| 42 | +from zarr.core.metadata.v3 import ArrayV3Metadata, DataType |
42 | 43 | from zarr.core.sync import sync |
43 | 44 | from zarr.errors import ContainsArrayError, ContainsGroupError |
44 | 45 | from zarr.storage import LocalStore, MemoryStore, StorePath |
45 | 46 |
|
46 | 47 | if TYPE_CHECKING: |
47 | 48 | from zarr.core.array_spec import ArrayConfigLike |
| 49 | + from zarr.core.metadata.v2 import ArrayV2Metadata |
48 | 50 |
|
49 | 51 |
|
50 | 52 | @pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"]) |
@@ -1259,16 +1261,26 @@ async def test_create_array_v2_no_shards(store: MemoryStore) -> None: |
1259 | 1261 |
|
1260 | 1262 |
|
1261 | 1263 | @pytest.mark.parametrize("store", ["memory"], indirect=True) |
1262 | | -async def test_create_array_data(store: Store) -> None: |
| 1264 | +@pytest.mark.parametrize("impl", ["sync", "async"]) |
| 1265 | +async def test_create_array_data(impl: Literal["sync", "async"], store: Store) -> None: |
1263 | 1266 | """ |
1264 | 1267 | Test that we can invoke ``create_array`` with a ``data`` parameter. |
1265 | 1268 | """ |
1266 | 1269 | data = np.arange(10) |
1267 | | - arr = await create_array(store, name="foo", data=data) |
1268 | | - stored = await arr._get_selection( |
1269 | | - BasicIndexer(..., shape=arr.shape, chunk_grid=arr.metadata.chunk_grid), |
1270 | | - prototype=default_buffer_prototype(), |
1271 | | - ) |
| 1270 | + name = "foo" |
| 1271 | + arr: AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata] | Array |
| 1272 | + if impl == "sync": |
| 1273 | + arr = sync_api.create_array(store, name=name, data=data) |
| 1274 | + stored = arr[:] |
| 1275 | + elif impl == "async": |
| 1276 | + arr = await create_array(store, name=name, data=data, zarr_format=3) |
| 1277 | + stored = await arr._get_selection( |
| 1278 | + BasicIndexer(..., shape=arr.shape, chunk_grid=arr.metadata.chunk_grid), |
| 1279 | + prototype=default_buffer_prototype(), |
| 1280 | + ) |
| 1281 | + else: |
| 1282 | + raise ValueError(f"Invalid impl: {impl}") |
| 1283 | + |
1272 | 1284 | assert np.array_equal(stored, data) |
1273 | 1285 |
|
1274 | 1286 |
|
|
0 commit comments