|
57 | 57 | from zarr.core.config import config |
58 | 58 | from zarr.core.metadata import ArrayV2Metadata, ArrayV3Metadata |
59 | 59 | from zarr.core.metadata.v3 import V3JsonEncoder |
60 | | -from zarr.core.sync import SyncMixin, _collect_aiterator, sync |
| 60 | +from zarr.core.sync import SyncMixin, sync |
61 | 61 | from zarr.errors import ( |
62 | 62 | ContainsArrayError, |
63 | 63 | ContainsGroupError, |
@@ -1435,7 +1435,7 @@ async def create_hierarchy( |
1435 | 1435 | semaphore = asyncio.Semaphore(config.get("async.concurrency")) |
1436 | 1436 |
|
1437 | 1437 | try: |
1438 | | - async for node in create_hierarchy_a( |
| 1438 | + async for node in create_hierarchy( |
1439 | 1439 | store=self.store, |
1440 | 1440 | path=self.path, |
1441 | 1441 | nodes=nodes, |
@@ -2081,7 +2081,7 @@ def create_hierarchy( |
2081 | 2081 | nodes: dict[str, ArrayV2Metadata | ArrayV3Metadata | GroupMetadata], |
2082 | 2082 | *, |
2083 | 2083 | overwrite: bool = False, |
2084 | | - ) -> Iterator[AsyncGroup | AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]]: |
| 2084 | + ) -> Iterator[Group | Array]: |
2085 | 2085 | """ |
2086 | 2086 | Create a hierarchy of arrays or groups rooted at this group. |
2087 | 2087 |
|
@@ -2116,7 +2116,8 @@ def create_hierarchy( |
2116 | 2116 | <AsyncGroup memory://123209880766144/a/b/c> |
2117 | 2117 | <AsyncGroup memory://123209880766144/a/b> |
2118 | 2118 | """ |
2119 | | - yield from self._sync_iter(self._async_group.create_hierarchy(nodes, overwrite=overwrite)) |
| 2119 | + for node in self._sync_iter(self._async_group.create_hierarchy(nodes, overwrite=overwrite)): |
| 2120 | + yield _parse_async_node(node) |
2120 | 2121 |
|
2121 | 2122 | def keys(self) -> Generator[str, None]: |
2122 | 2123 | """Return an iterator over group member names. |
@@ -2854,7 +2855,7 @@ def array( |
2854 | 2855 | ) |
2855 | 2856 |
|
2856 | 2857 |
|
2857 | | -async def create_hierarchy_a( |
| 2858 | +async def create_hierarchy( |
2858 | 2859 | *, |
2859 | 2860 | store: Store, |
2860 | 2861 | path: str, |
@@ -2967,58 +2968,11 @@ async def create_hierarchy_a( |
2967 | 2968 | k: v for k, v in nodes_parsed.items() if k not in redundant_implicit_groups |
2968 | 2969 | } |
2969 | 2970 |
|
2970 | | - async for node in create_nodes_a( |
2971 | | - store=store, path=path, nodes=nodes_parsed, semaphore=semaphore |
2972 | | - ): |
| 2971 | + async for node in create_nodes(store=store, path=path, nodes=nodes_parsed, semaphore=semaphore): |
2973 | 2972 | yield node |
2974 | 2973 |
|
2975 | 2974 |
|
2976 | | -def create_hierarchy( |
2977 | | - store: Store, |
2978 | | - path: str, |
2979 | | - nodes: dict[str, GroupMetadata | ArrayV2Metadata | ArrayV3Metadata], |
2980 | | - overwrite: bool = False, |
2981 | | - allow_root: bool = True, |
2982 | | -) -> Iterator[Group | Array]: |
2983 | | - """ |
2984 | | - Create a complete zarr hierarchy concurrently. Groups that are implicitly defined by the input |
2985 | | - will be created as needed. |
2986 | | -
|
2987 | | - This function takes a parsed hierarchy dictionary and creates all the nodes in the hierarchy |
2988 | | - concurrently. Arrays and Groups are yielded in the order they are created. |
2989 | | -
|
2990 | | - Parameters |
2991 | | - ---------- |
2992 | | - store : Store |
2993 | | - The storage backend to use. |
2994 | | - path : str |
2995 | | - The name of the root of the created hierarchy. Every key in ``nodes`` will be prefixed with |
2996 | | - ``path`` prior to creating nodes. |
2997 | | - nodes : dict[str, GroupMetadata | ArrayV3Metadata | ArrayV2Metadata] |
2998 | | - A dictionary defining the hierarchy. The keys are the paths of the nodes |
2999 | | - in the hierarchy, and the values are the metadata of the nodes. The |
3000 | | - metadata must be either an instance of GroupMetadata, ArrayV3Metadata |
3001 | | - or ArrayV2Metadata. |
3002 | | - allow_root : bool |
3003 | | - Whether to allow a root node to be created. If ``False``, attempting to create a root node |
3004 | | - will result in an error. Use this option when calling this function as part of a method |
3005 | | - defined on ``AsyncGroup`` instances, because in this case the root node has already been |
3006 | | - created. |
3007 | | -
|
3008 | | - Yields |
3009 | | - ------ |
3010 | | - Group | Array |
3011 | | - The created nodes in the order they are created. |
3012 | | - """ |
3013 | | - coro = create_hierarchy_a( |
3014 | | - store=store, path=path, nodes=nodes, overwrite=overwrite, allow_root=allow_root |
3015 | | - ) |
3016 | | - |
3017 | | - for result in sync(_collect_aiterator(coro)): |
3018 | | - yield _parse_async_node(result) |
3019 | | - |
3020 | | - |
3021 | | -async def create_nodes_a( |
| 2975 | +async def create_nodes( |
3022 | 2976 | *, |
3023 | 2977 | store: Store, |
3024 | 2978 | path: str, |
@@ -3119,46 +3073,6 @@ async def create_nodes_a( |
3119 | 3073 | continue |
3120 | 3074 |
|
3121 | 3075 |
|
3122 | | -def create_nodes( |
3123 | | - *, |
3124 | | - store: Store, |
3125 | | - path: str, |
3126 | | - nodes: dict[str, GroupMetadata | ArrayV2Metadata | ArrayV3Metadata], |
3127 | | - semaphore: asyncio.Semaphore | None = None, |
3128 | | -) -> Iterator[Group | Array]: |
3129 | | - """Create a collection of arrays and / or groups concurrently. |
3130 | | -
|
3131 | | - Note: no attempt is made to validate that these arrays and / or groups collectively form a |
3132 | | - valid Zarr hierarchy. It is the responsibility of the caller of this function to ensure that |
3133 | | - the ``nodes`` parameter satisfies any correctness constraints. |
3134 | | -
|
3135 | | - Parameters |
3136 | | - ---------- |
3137 | | - store : Store |
3138 | | - The storage backend to use. |
3139 | | - path : str |
3140 | | - The name of the root of the created hierarchy. Every key in ``nodes`` will be prefixed with |
3141 | | - ``path`` prior to creating nodes. |
3142 | | - nodes : dict[str, GroupMetadata | ArrayV3Metadata | ArrayV2Metadata] |
3143 | | - A dictionary defining the hierarchy. The keys are the paths of the nodes |
3144 | | - in the hierarchy, and the values are the metadata of the nodes. The |
3145 | | - metadata must be either an instance of GroupMetadata, ArrayV3Metadata |
3146 | | - or ArrayV2Metadata. |
3147 | | - semaphore : asyncio.Semaphore | None |
3148 | | - An optional semaphore to limit the number of concurrent tasks. If not |
3149 | | - provided, the number of concurrent tasks is unlimited. |
3150 | | -
|
3151 | | - Yields |
3152 | | - ------ |
3153 | | - Group | Array |
3154 | | - The created nodes in the order they are created. |
3155 | | - """ |
3156 | | - coro = create_nodes_a(store=store, path=path, nodes=nodes, semaphore=semaphore) |
3157 | | - |
3158 | | - for result in sync(_collect_aiterator(coro)): |
3159 | | - yield _parse_async_node(result) |
3160 | | - |
3161 | | - |
3162 | 3076 | T = TypeVar("T") |
3163 | 3077 |
|
3164 | 3078 |
|
@@ -3611,7 +3525,7 @@ def _persist_metadata( |
3611 | 3525 | ) |
3612 | 3526 |
|
3613 | 3527 |
|
3614 | | -async def _create_rooted_hierarchy_a( |
| 3528 | +async def create_rooted_hierarchy( |
3615 | 3529 | *, |
3616 | 3530 | store: Store, |
3617 | 3531 | path: str, |
@@ -3639,25 +3553,8 @@ async def _create_rooted_hierarchy_a( |
3639 | 3553 |
|
3640 | 3554 | nodes_created = { |
3641 | 3555 | x.path: x |
3642 | | - async for x in create_hierarchy_a( |
| 3556 | + async for x in create_hierarchy( |
3643 | 3557 | store=store, path=path, nodes=nodes, semaphore=semaphore, overwrite=overwrite |
3644 | 3558 | ) |
3645 | 3559 | } |
3646 | 3560 | return nodes_created[_join_paths([path, root_key])] |
3647 | | - |
3648 | | - |
3649 | | -def _create_rooted_hierarchy( |
3650 | | - *, |
3651 | | - store: Store, |
3652 | | - path: str, |
3653 | | - nodes: dict[str, GroupMetadata | ArrayV2Metadata | ArrayV3Metadata], |
3654 | | - overwrite: bool = False, |
3655 | | -) -> Group | Array: |
3656 | | - """ |
3657 | | - Create a ``Group`` from a store and a dict of metadata documents. Calls the async method |
3658 | | - ``_create_rooted_hierarchy`` and waits for the result. |
3659 | | - """ |
3660 | | - async_node = sync( |
3661 | | - _create_rooted_hierarchy_a(store=store, path=path, nodes=nodes, overwrite=overwrite) |
3662 | | - ) |
3663 | | - return _parse_async_node(async_node) |
0 commit comments