Skip to content

Commit 0b5483a

Browse files
authored
[v3] clean up create_array signatures in group/asyncgroup classes (#2132)
* clean up create_array signatures in group/asyncgroup classes * fix members test
1 parent 2f9cf22 commit 0b5483a

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

src/zarr/core/group.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,21 +311,23 @@ def info(self) -> None:
311311

312312
async def create_group(
313313
self,
314-
path: str,
314+
name: str,
315+
*,
315316
exists_ok: bool = False,
316317
attributes: dict[str, Any] | None = None,
317318
) -> AsyncGroup:
318319
attributes = attributes or {}
319320
return await type(self).create(
320-
self.store_path / path,
321+
self.store_path / name,
321322
attributes=attributes,
322323
exists_ok=exists_ok,
323324
zarr_format=self.metadata.zarr_format,
324325
)
325326

326327
async def create_array(
327328
self,
328-
path: str,
329+
name: str,
330+
*,
329331
shape: ChunkCoords,
330332
dtype: npt.DTypeLike = "float64",
331333
fill_value: Any | None = None,
@@ -356,7 +358,7 @@ async def create_array(
356358
357359
Parameters
358360
----------
359-
path: str
361+
name: str
360362
The name of the array.
361363
shape: tuple[int, ...]
362364
The shape of the array.
@@ -392,7 +394,7 @@ async def create_array(
392394
393395
"""
394396
return await AsyncArray.create(
395-
self.store_path / path,
397+
self.store_path / name,
396398
shape=shape,
397399
dtype=dtype,
398400
chunk_shape=chunk_shape,
@@ -789,7 +791,7 @@ def create_array(
789791
return Array(
790792
self._sync(
791793
self._async_group.create_array(
792-
path=name,
794+
name=name,
793795
shape=shape,
794796
dtype=dtype,
795797
fill_value=fill_value,
@@ -912,7 +914,7 @@ def array(
912914
return Array(
913915
self._sync(
914916
self._async_group.create_array(
915-
path=name,
917+
name=name,
916918
shape=shape,
917919
dtype=dtype,
918920
fill_value=fill_value,

tests/v3/test_group.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,11 @@ async def test_asyncgroup_getitem(store: LocalStore | MemoryStore, zarr_format:
564564
"""
565565
agroup = await AsyncGroup.create(store=store, zarr_format=zarr_format)
566566

567-
sub_array_path = "sub_array"
567+
array_name = "sub_array"
568568
sub_array = await agroup.create_array(
569-
path=sub_array_path, shape=(10,), dtype="uint8", chunk_shape=(2,)
569+
name=array_name, shape=(10,), dtype="uint8", chunk_shape=(2,)
570570
)
571-
assert await agroup.getitem(sub_array_path) == sub_array
571+
assert await agroup.getitem(array_name) == sub_array
572572

573573
sub_group_path = "sub_group"
574574
sub_group = await agroup.create_group(sub_group_path, attributes={"foo": 100})
@@ -581,29 +581,29 @@ async def test_asyncgroup_getitem(store: LocalStore | MemoryStore, zarr_format:
581581

582582
async def test_asyncgroup_delitem(store: LocalStore | MemoryStore, zarr_format: ZarrFormat) -> None:
583583
agroup = await AsyncGroup.create(store=store, zarr_format=zarr_format)
584-
sub_array_path = "sub_array"
584+
array_name = "sub_array"
585585
_ = await agroup.create_array(
586-
path=sub_array_path, shape=(10,), dtype="uint8", chunk_shape=(2,), attributes={"foo": 100}
586+
name=array_name, shape=(10,), dtype="uint8", chunk_shape=(2,), attributes={"foo": 100}
587587
)
588-
await agroup.delitem(sub_array_path)
588+
await agroup.delitem(array_name)
589589

590590
# todo: clean up the code duplication here
591591
if zarr_format == 2:
592-
assert not await agroup.store_path.store.exists(sub_array_path + "/" + ".zarray")
593-
assert not await agroup.store_path.store.exists(sub_array_path + "/" + ".zattrs")
592+
assert not await agroup.store_path.store.exists(array_name + "/" + ".zarray")
593+
assert not await agroup.store_path.store.exists(array_name + "/" + ".zattrs")
594594
elif zarr_format == 3:
595-
assert not await agroup.store_path.store.exists(sub_array_path + "/" + "zarr.json")
595+
assert not await agroup.store_path.store.exists(array_name + "/" + "zarr.json")
596596
else:
597597
raise AssertionError
598598

599599
sub_group_path = "sub_group"
600600
_ = await agroup.create_group(sub_group_path, attributes={"foo": 100})
601601
await agroup.delitem(sub_group_path)
602602
if zarr_format == 2:
603-
assert not await agroup.store_path.store.exists(sub_array_path + "/" + ".zgroup")
604-
assert not await agroup.store_path.store.exists(sub_array_path + "/" + ".zattrs")
603+
assert not await agroup.store_path.store.exists(array_name + "/" + ".zgroup")
604+
assert not await agroup.store_path.store.exists(array_name + "/" + ".zattrs")
605605
elif zarr_format == 3:
606-
assert not await agroup.store_path.store.exists(sub_array_path + "/" + "zarr.json")
606+
assert not await agroup.store_path.store.exists(array_name + "/" + "zarr.json")
607607
else:
608608
raise AssertionError
609609

@@ -615,7 +615,7 @@ async def test_asyncgroup_create_group(
615615
agroup = await AsyncGroup.create(store=store, zarr_format=zarr_format)
616616
sub_node_path = "sub_group"
617617
attributes = {"foo": 999}
618-
subnode = await agroup.create_group(path=sub_node_path, attributes=attributes)
618+
subnode = await agroup.create_group(name=sub_node_path, attributes=attributes)
619619

620620
assert isinstance(subnode, AsyncGroup)
621621
assert subnode.attrs == attributes
@@ -645,7 +645,7 @@ async def test_asyncgroup_create_array(
645645

646646
sub_node_path = "sub_array"
647647
subnode = await agroup.create_array(
648-
path=sub_node_path,
648+
name=sub_node_path,
649649
shape=shape,
650650
dtype=dtype,
651651
chunk_shape=chunk_shape,
@@ -684,11 +684,11 @@ async def test_group_members_async(store: LocalStore | MemoryStore):
684684
GroupMetadata(),
685685
store_path=StorePath(store=store, path="root"),
686686
)
687-
a0 = await group.create_array("a0", (1,))
687+
a0 = await group.create_array("a0", shape=(1,))
688688
g0 = await group.create_group("g0")
689-
a1 = await g0.create_array("a1", (1,))
689+
a1 = await g0.create_array("a1", shape=(1,))
690690
g1 = await g0.create_group("g1")
691-
a2 = await g1.create_array("a2", (1,))
691+
a2 = await g1.create_array("a2", shape=(1,))
692692
g2 = await g1.create_group("g2")
693693

694694
# immediate children

0 commit comments

Comments
 (0)