Skip to content

Commit df2bdc6

Browse files
committed
docstrings
1 parent 8245e80 commit df2bdc6

File tree

1 file changed

+42
-18
lines changed

1 file changed

+42
-18
lines changed

src/zarr/core/group.py

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,21 +1400,34 @@ async def create_hierarchy(
14001400
"""
14011401
Create a hierarchy of arrays or groups rooted at this group.
14021402
1403-
This method takes a dictionary where the keys are the names of the arrays or groups
1404-
to create and the values are the metadata or objects representing the arrays or groups.
1403+
This function will parse its input to ensure that the hierarchy is complete. Any implicit groups
1404+
will be inserted as needed. For example, an input like
1405+
```{'a/b': GroupMetadata}``` will be parsed to
1406+
```{'': GroupMetadata, 'a': GroupMetadata, 'b': Groupmetadata}```.
14051407
1406-
The method returns an asynchronous iterator over the created nodes.
1408+
Explicitly specifying a root group, e.g. with ``nodes = {'': GroupMetadata()}`` is an error
1409+
because this group instance is the root group.
1410+
1411+
After input parsing, this function then creates all the nodes in the hierarchy concurrently.
1412+
1413+
Arrays and Groups are yielded in the order they are created. This order is not stable and
1414+
should not be relied on.
14071415
14081416
Parameters
14091417
----------
1410-
nodes : A dictionary representing the hierarchy to create
1411-
1418+
nodes : A dictionary representing the hierarchy to create. The keys should be paths relative to this group
1419+
and the values should be the metadata for the arrays or groups to create.
14121420
overwrite : bool
1413-
Whether or not existing arrays / groups should be replaced.
1421+
Whether to overwrite existing nodes. Defaults to ``False``, in which case an error is
1422+
raised instead of overwriting an existing array or group.
14141423
1415-
Returns
1424+
This function will not erase an existing group unless that group is explicitly named in
1425+
``nodes``. If ``nodes`` defines implicit groups, e.g. ``{`'a/b/c': GroupMetadata}``, and a
1426+
group already exists at path ``a``, then this function will leave the group at ``a`` as-is.
1427+
1428+
Yields
14161429
-------
1417-
An asynchronous iterator of (str, AsyncArray | AsyncGroup) pairs.
1430+
tuple[str, AsyncArray | AsyncGroup].
14181431
"""
14191432
# check that all the nodes have the same zarr_format as Self
14201433
prefix = self.path
@@ -2081,24 +2094,35 @@ def create_hierarchy(
20812094
"""
20822095
Create a hierarchy of arrays or groups rooted at this group.
20832096
2084-
This method takes a dictionary where the keys are the names of the arrays or groups
2085-
to create and the values are the metadata objects for the arrays or groups.
2097+
This function will parse its input to ensure that the hierarchy is complete. Any implicit groups
2098+
will be inserted as needed. For example, an input like
2099+
```{'a/b': GroupMetadata}``` will be parsed to
2100+
```{'': GroupMetadata, 'a': GroupMetadata, 'b': Groupmetadata}```.
20862101
2087-
This method returns an iterator of created Group or Array objects.
2102+
Explicitly specifying a root group, e.g. with ``nodes = {'': GroupMetadata()}`` is an error
2103+
because this group instance is the root group.
2104+
2105+
After input parsing, this function then creates all the nodes in the hierarchy concurrently.
2106+
2107+
Arrays and Groups are yielded in the order they are created. This order is not stable and
2108+
should not be relied on.
20882109
2089-
Note: this method will create additional groups as needed to ensure that a hierarchy is
2090-
complete. Usage like ``create_hierarchy({'a/b': GroupMetadata()})`` defines an implicit
2091-
group at ``a``. This function will ensure that the group at ``a`` exists, first by checking
2092-
if one already exists, and if not, creating one.
20932110
20942111
Parameters
20952112
----------
2096-
nodes : A dictionary representing the hierarchy to create. The keys should be relative paths
2113+
nodes : A dictionary representing the hierarchy to create. The keys should be paths relative to this group
20972114
and the values should be the metadata for the arrays or groups to create.
2115+
overwrite : bool
2116+
Whether to overwrite existing nodes. Defaults to ``False``, in which case an error is
2117+
raised instead of overwriting an existing array or group.
20982118
2099-
Returns
2119+
This function will not erase an existing group unless that group is explicitly named in
2120+
``nodes``. If ``nodes`` defines implicit groups, e.g. ``{`'a/b/c': GroupMetadata}``, and a
2121+
group already exists at path ``a``, then this function will leave the group at ``a`` as-is.
2122+
2123+
Yields
21002124
-------
2101-
An iterator of (name, Array or Group) tuples.
2125+
tuple[str, Array | Group].
21022126
21032127
Examples
21042128
--------

0 commit comments

Comments
 (0)