@@ -3445,14 +3445,16 @@ def _persist_metadata(
34453445 )
34463446
34473447
3448- async def _from_flat (
3448+ async def _create_rooted_hierarchy (
34493449 store_path : StorePath ,
34503450 * ,
34513451 nodes : dict [str , GroupMetadata | ArrayV2Metadata | ArrayV3Metadata ],
34523452 overwrite : bool = False ,
3453- ) -> AsyncGroup :
3453+ ) -> AsyncGroup | AsyncArray [ ArrayV2Metadata ] | AsyncArray [ ArrayV3Metadata ] :
34543454 """
3455- Create an ``AsyncGroup`` from a store + a dict of nodes.
3455+ Create an ``AsyncGroup`` or ``AsyncArray`` from a store and a dict of metadata documents.
3456+ This function ensures that its input contains a specification of a root node,
3457+ calls ``create_hierarchy`` to create nodes, and returns the root node of the hierarchy.
34563458 """
34573459 roots = _get_roots (nodes )
34583460 if len (roots ) != 1 :
@@ -3476,7 +3478,25 @@ async def _from_flat(
34763478 }
34773479 # the names of the created nodes will be relative to the store_path instance
34783480 root_relative_to_store_path = _join_paths ([store_path .path , root ])
3479- root_group = nodes_created [root_relative_to_store_path ]
3480- if not isinstance (root_group , AsyncGroup ):
3481- raise TypeError ("Invalid root node returned from create_hierarchy." )
3482- return root_group
3481+ return nodes_created [root_relative_to_store_path ]
3482+
3483+
3484+ def _create_rooted_hierarchy_sync (
3485+ store_path : StorePath ,
3486+ * ,
3487+ nodes : dict [str , GroupMetadata | ArrayV2Metadata | ArrayV3Metadata ],
3488+ overwrite : bool = False ,
3489+ ) -> Group | Array :
3490+ """
3491+ Create a ``Group`` from a store and a dict of metadata documents. Calls the async method
3492+ ``_create_rooted_hierarchy`` and waits for the result.
3493+ """
3494+ async_node = sync (
3495+ _create_rooted_hierarchy (store_path = store_path , nodes = nodes , overwrite = overwrite )
3496+ )
3497+ if isinstance (async_node , AsyncGroup ):
3498+ return Group (async_node )
3499+ elif isinstance (async_node , AsyncArray ):
3500+ return Array (async_node )
3501+ else :
3502+ raise TypeError (f"Unexpected node type: { type (async_node )} " )
0 commit comments