|
10 | 10 | from functools import partial |
11 | 11 | from itertools import accumulate |
12 | 12 | from pathlib import PurePosixPath |
13 | | -from typing import TYPE_CHECKING, Literal, TypeVar, assert_never, cast, overload |
| 13 | +from typing import TYPE_CHECKING, Literal, Self, TypeVar, assert_never, cast, overload |
14 | 14 |
|
15 | 15 | import numpy as np |
16 | 16 | import numpy.typing as npt |
@@ -426,6 +426,27 @@ class AsyncGroup: |
426 | 426 | metadata: GroupMetadata |
427 | 427 | store_path: StorePath |
428 | 428 |
|
| 429 | + # TODO: make this correct and work |
| 430 | + # TODO: ensure that this can be bound properly to subclass of AsyncGroup |
| 431 | + @classmethod |
| 432 | + async def from_flat( |
| 433 | + cls, |
| 434 | + store: StoreLike, |
| 435 | + *, |
| 436 | + nodes: dict[str, GroupMetadata | ArrayV2Metadata | ArrayV3Metadata], |
| 437 | + overwrite: bool = False) -> Self: |
| 438 | + |
| 439 | + if overwrite: |
| 440 | + store_path = await make_store_path(store, mode='w') |
| 441 | + else: |
| 442 | + store_path = await make_store_path(store, mode='w-') |
| 443 | + semaphore = asyncio.Semaphore(config.get("async.concurrency")) |
| 444 | + |
| 445 | + nodes_created = {x.name: x async for x in create_hierarchy( |
| 446 | + store_path=store_path, nodes=nodes, semaphore=semaphore |
| 447 | + )} |
| 448 | + return nodes_created[''] |
| 449 | + |
429 | 450 | @classmethod |
430 | 451 | async def from_store( |
431 | 452 | cls, |
@@ -1269,15 +1290,6 @@ async def require_array( |
1269 | 1290 |
|
1270 | 1291 | return ds |
1271 | 1292 |
|
1272 | | - async def _create_nodes( |
1273 | | - self, nodes: dict[str, GroupMetadata | ArrayV2Metadata | ArrayV3Metadata] |
1274 | | - ) -> AsyncIterator[AsyncGroup | AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]]: |
1275 | | - """ |
1276 | | - Create a set of arrays or groups rooted at this group. |
1277 | | - """ |
1278 | | - async for node in create_hierarchy(store_path=self.store_path, nodes=nodes): |
1279 | | - yield node |
1280 | | - |
1281 | 1293 | async def update_attributes(self, new_attributes: dict[str, Any]) -> AsyncGroup: |
1282 | 1294 | """Update group attributes. |
1283 | 1295 |
|
@@ -1731,6 +1743,17 @@ async def move(self, source: str, dest: str) -> None: |
1731 | 1743 | @dataclass(frozen=True) |
1732 | 1744 | class Group(SyncMixin): |
1733 | 1745 | _async_group: AsyncGroup |
| 1746 | + |
| 1747 | + @classmethod |
| 1748 | + def from_flat( |
| 1749 | + cls, |
| 1750 | + store: StoreLike, |
| 1751 | + *, |
| 1752 | + nodes: dict[str, GroupMetadata | ArrayV2Metadata | ArrayV3Metadata], |
| 1753 | + overwrite: bool = False) -> Group: |
| 1754 | + nodes = sync(AsyncGroup.from_flat(store, nodes=nodes, overwrite=overwrite)) |
| 1755 | + # return the root node of the hierarchy |
| 1756 | + return nodes[''] |
1734 | 1757 |
|
1735 | 1758 | @classmethod |
1736 | 1759 | def from_store( |
|
0 commit comments