|
10 | 10 |
|
11 | 11 | if TYPE_CHECKING:
|
12 | 12 | from zarr.core.common import ZarrFormat
|
13 |
| - from zarr.core.group import AsyncGroup, GroupMetadata |
| 13 | + from zarr.core.group import GroupMetadata |
14 | 14 | from zarr.core.metadata import ArrayMetadata
|
15 | 15 |
|
16 | 16 |
|
17 |
| -def _build_parents(store_path: StorePath, zarr_format: ZarrFormat) -> list[AsyncGroup]: |
18 |
| - from zarr.core.group import AsyncGroup, GroupMetadata |
| 17 | +def _build_parents(store_path: StorePath, zarr_format: ZarrFormat) -> dict[str, GroupMetadata]: |
| 18 | + from zarr.core.group import GroupMetadata |
19 | 19 |
|
20 |
| - store = store_path.store |
21 | 20 | path = store_path.path
|
22 | 21 | if not path:
|
23 |
| - return [] |
| 22 | + return {} |
24 | 23 |
|
25 | 24 | required_parts = path.split("/")[:-1]
|
26 |
| - parents = [ |
27 |
| - # the root group |
28 |
| - AsyncGroup( |
29 |
| - metadata=GroupMetadata(zarr_format=zarr_format), |
30 |
| - store_path=StorePath(store=store, path=""), |
31 |
| - ) |
32 |
| - ] |
| 25 | + |
| 26 | + # the root group |
| 27 | + parents = {"": GroupMetadata(zarr_format=zarr_format)} |
33 | 28 |
|
34 | 29 | for i, part in enumerate(required_parts):
|
35 |
| - p = "/".join(required_parts[:i] + [part]) |
36 |
| - parents.append( |
37 |
| - AsyncGroup( |
38 |
| - metadata=GroupMetadata(zarr_format=zarr_format), |
39 |
| - store_path=StorePath(store=store, path=p), |
40 |
| - ) |
41 |
| - ) |
| 30 | + parent_path = "/".join(required_parts[:i] + [part]) |
| 31 | + parents[parent_path] = GroupMetadata(zarr_format=zarr_format) |
42 | 32 |
|
43 | 33 | return parents
|
44 | 34 |
|
@@ -69,15 +59,19 @@ async def save_metadata(
|
69 | 59 | parents = _build_parents(store_path, metadata.zarr_format)
|
70 | 60 | ensure_array_awaitables = []
|
71 | 61 |
|
72 |
| - for parent in parents: |
| 62 | + for parent_path, parent_metadata in parents.items(): |
| 63 | + parent_store_path = StorePath(store_path.store, parent_path) |
| 64 | + |
73 | 65 | # Error if an array already exists at any parent location. Only groups can have child nodes.
|
74 | 66 | ensure_array_awaitables.append(
|
75 |
| - ensure_no_existing_node(parent.store_path, metadata.zarr_format, node_type="array") |
| 67 | + ensure_no_existing_node( |
| 68 | + parent_store_path, parent_metadata.zarr_format, node_type="array" |
| 69 | + ) |
76 | 70 | )
|
77 | 71 | set_awaitables.extend(
|
78 | 72 | [
|
79 |
| - (parent.store_path / key).set_if_not_exists(value) |
80 |
| - for key, value in parent.metadata.to_buffer_dict( |
| 73 | + (parent_store_path / key).set_if_not_exists(value) |
| 74 | + for key, value in parent_metadata.to_buffer_dict( |
81 | 75 | default_buffer_prototype()
|
82 | 76 | ).items()
|
83 | 77 | ]
|
|
0 commit comments