Skip to content

Commit 9f0ccfa

Browse files
committed
refactor: remove path kwarg, bring back ImplicitGroupMetadata
1 parent a2547b3 commit 9f0ccfa

File tree

6 files changed

+262
-268
lines changed

6 files changed

+262
-268
lines changed

src/zarr/api/synchronous.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,12 +1142,11 @@ def zeros_like(a: ArrayLike, **kwargs: Any) -> Array:
11421142

11431143

11441144
def create_hierarchy(
1145+
*,
11451146
store: Store,
1146-
path: str,
11471147
nodes: dict[str, GroupMetadata | ArrayV2Metadata | ArrayV3Metadata],
11481148
overwrite: bool = False,
1149-
allow_root: bool = True,
1150-
) -> Iterator[Group | Array]:
1149+
) -> Iterator[tuple[str, Group | Array]]:
11511150
"""
11521151
Create a complete zarr hierarchy from a collection of metadata objects.
11531152
@@ -1161,36 +1160,29 @@ def create_hierarchy(
11611160
----------
11621161
store : Store
11631162
The storage backend to use.
1164-
path : str
1165-
The name of the root of the created hierarchy. Every key in ``nodes`` will be prefixed with
1166-
``path`` prior to creating nodes.
11671163
nodes : dict[str, GroupMetadata | ArrayV3Metadata | ArrayV2Metadata]
11681164
A dictionary defining the hierarchy. The keys are the paths of the nodes
11691165
in the hierarchy, and the values are the metadata of the nodes. The
11701166
metadata must be either an instance of GroupMetadata, ArrayV3Metadata
11711167
or ArrayV2Metadata.
1172-
allow_root : bool
1173-
Whether to allow a root node to be created. If ``False``, attempting to create a root node
1174-
will result in an error. Use this option when calling this function as part of a method
1175-
defined on ``AsyncGroup`` instances, because in this case the root node has already been
1176-
created.
1168+
overwrite : bool
1169+
Whether to overwrite existing nodes. Defaults to ``False``, in which case an error will be
1170+
raised instead of overwriting an existing array or group.
11771171
11781172
Yields
11791173
------
1180-
Group | Array
1181-
The created nodes in the order they are created.
1174+
tuple[str, Group | Array]
1175+
(key, node) pairs the order they are created.
11821176
"""
1183-
coro = async_api.create_hierarchy(
1184-
store=store, path=path, nodes=nodes, overwrite=overwrite, allow_root=allow_root
1185-
)
1177+
coro = async_api.create_hierarchy(store=store, nodes=nodes, overwrite=overwrite)
11861178

1187-
for result in sync(_collect_aiterator(coro)):
1188-
yield _parse_async_node(result)
1179+
for key, value in sync(_collect_aiterator(coro)):
1180+
yield key, _parse_async_node(value)
11891181

11901182

11911183
def create_nodes(
1192-
*, store: Store, path: str, nodes: dict[str, GroupMetadata | ArrayV2Metadata | ArrayV3Metadata]
1193-
) -> Iterator[Group | Array]:
1184+
*, store: Store, nodes: dict[str, GroupMetadata | ArrayV2Metadata | ArrayV3Metadata]
1185+
) -> Iterator[tuple[str, Group | Array]]:
11941186
"""Create a collection of arrays and / or groups concurrently.
11951187
11961188
Note: no attempt is made to validate that these arrays and / or groups collectively form a
@@ -1201,9 +1193,6 @@ def create_nodes(
12011193
----------
12021194
store : Store
12031195
The storage backend to use.
1204-
path : str
1205-
The name of the root of the created hierarchy. Every key in ``nodes`` will be prefixed with
1206-
``path`` prior to creating nodes.
12071196
nodes : dict[str, GroupMetadata | ArrayV3Metadata | ArrayV2Metadata]
12081197
A dictionary defining the hierarchy. The keys are the paths of the nodes
12091198
in the hierarchy, and the values are the metadata of the nodes. The
@@ -1215,16 +1204,15 @@ def create_nodes(
12151204
Group | Array
12161205
The created nodes.
12171206
"""
1218-
coro = async_api.create_nodes(store=store, path=path, nodes=nodes)
1207+
coro = async_api.create_nodes(store=store, nodes=nodes)
12191208

1220-
for result in sync(_collect_aiterator(coro)):
1221-
yield _parse_async_node(result)
1209+
for key, value in sync(_collect_aiterator(coro)):
1210+
yield key, _parse_async_node(value)
12221211

12231212

12241213
def create_rooted_hierarchy(
12251214
*,
12261215
store: Store,
1227-
path: str,
12281216
nodes: dict[str, GroupMetadata | ArrayV2Metadata | ArrayV3Metadata],
12291217
overwrite: bool = False,
12301218
) -> Group | Array:
@@ -1252,7 +1240,7 @@ def create_rooted_hierarchy(
12521240
Group | Array
12531241
"""
12541242
async_node = sync(
1255-
async_api.create_rooted_hierarchy(store=store, path=path, nodes=nodes, overwrite=overwrite)
1243+
async_api.create_rooted_hierarchy(store=store, nodes=nodes, overwrite=overwrite)
12561244
)
12571245
return _parse_async_node(async_node)
12581246

0 commit comments

Comments
 (0)