@@ -2866,15 +2866,10 @@ async def create_hierarchy(
28662866 """
28672867 Create a complete zarr hierarchy from a collection of metadata objects.
28682868
2869- This function will parse its input to ensure that the hierarchy is valid. In this context,
2870- "valid" means that the following requirements are met:
2871- * All nodes have the same zarr format.
2872- * There are no nodes descending from arrays.
2873- * There are no implicit groups. Any implicit groups will be inserted as needed. For example,
2874- an input like ```{'a': GroupMetadata, 'a/b/c': GroupMetadata}``` defines an implicit group at
2875- the path ```a/b```, and also at the root of the hierarchy, which we denote with the empty string.
2876- After parsing, that group will be added and the input will be:
2877- ```{'': GroupMetadata, 'a': GroupMetadata, 'a/b': GroupMetadata, 'a/b/c': GroupMetadata}```
2869+ This function will parse its input to ensure that the hierarchy is complete. Any implicit groups
2870+ will be inserted as needed. For example, an input like
2871+ ```{'a/b': GroupMetadata}``` will be parsed to
2872+ ```{'': GroupMetadata, 'a': GroupMetadata, 'b': Groupmetadata}```
28782873
28792874 After input parsing, this function then creates all the nodes in the hierarchy concurrently.
28802875
@@ -2886,22 +2881,38 @@ async def create_hierarchy(
28862881 store : Store
28872882 The storage backend to use.
28882883 nodes : dict[str, GroupMetadata | ArrayV3Metadata | ArrayV2Metadata]
2889- A dictionary defining the hierarchy. The keys are the paths of the nodes
2890- in the hierarchy, and the values are the metadata of the nodes. The
2891- metadata must be either an instance of GroupMetadata, ArrayV3Metadata
2892- or ArrayV2Metadata.
2884+ A dictionary defining the hierarchy. The keys are the paths of the nodes in the hierarchy,
2885+ relative to the root of the ``Store``. The root of the store can be specified with the empty
2886+ string ``''``. The values are instances of ``GroupMetadata`` or ``ArrayMetadata``. Note that
2887+ all values must have the same ``zarr_format`` -- it is an error to mix zarr versions in the
2888+ same hierarchy.
28932889 overwrite : bool
28942890 Whether to overwrite existing nodes. Defaults to ``False``, in which case an error is
28952891 raised instead of overwriting an existing array or group.
28962892
2893+ This function will not erase an existing group unless that group is explicitly named in
2894+ ``nodes``. If ``nodes`` defines implicit groups, e.g. ``{`'a/b/c': GroupMetadata}``, and a
2895+ group already exists at path ``a``, then this function will leave the group at ``a`` as-is.
2896+
28972897 Yields
28982898 ------
2899- AsyncGroup | AsyncArray
2900- The created nodes in the order they are created.
2899+ tuple[str, AsyncGroup | AsyncArray]
2900+ This function yields (path, node) pairs, in the order the nodes were created.
29012901
29022902 Examples
29032903 --------
2904-
2904+ from zarr.api.asynchronous import create_hierarchy
2905+ from zarr.storage import MemoryStore
2906+ from zarr.core.group import GroupMetadata
2907+ import asyncio
2908+ store = MemoryStore()
2909+ nodes = {'a': GroupMetadata(attributes={'name': 'leaf'})}
2910+
2911+ async def run():
2912+ print(dict([x async for x in create_hierarchy(store=store, nodes=nodes)]))
2913+
2914+ asyncio.run(run())
2915+ # {'a': <AsyncGroup memory://140345143770112/a>, '': <AsyncGroup memory://140345143770112>}
29052916 """
29062917 # normalize the keys to be valid paths
29072918 nodes_normed_keys = _normalize_path_keys (nodes )
0 commit comments