Skip to content

Commit 77f2938

Browse files
committed
clean up parents
1 parent 54ab9ef commit 77f2938

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/zarr/core/array.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
from asyncio import gather
55
from dataclasses import dataclass, field, replace
6+
from logging import getLogger
67
from typing import TYPE_CHECKING, Any, Literal, cast
78

89
import numpy as np
@@ -80,6 +81,8 @@
8081
# Array and AsyncArray are defined in the base ``zarr`` namespace
8182
__all__ = ["create_codec_pipeline", "parse_array_metadata"]
8283

84+
logger = getLogger(__name__)
85+
8386

8487
def parse_array_metadata(data: Any) -> ArrayV2Metadata | ArrayV3Metadata:
8588
if isinstance(data, ArrayV2Metadata | ArrayV3Metadata):
@@ -636,6 +639,8 @@ async def _save_metadata(self, metadata: ArrayMetadata, ensure_parents: bool = F
636639
# To enable zarr.create(store, path="a/b/c"), we need to create all the intermediate groups.
637640
parents = _build_parents(self)
638641

642+
logger.debug("Ensure parents: %s", parents)
643+
639644
for parent in parents:
640645
awaitables.extend(
641646
[
@@ -2385,11 +2390,9 @@ def chunks_initialized(array: Array | AsyncArray) -> tuple[str, ...]:
23852390
def _build_parents(node: AsyncArray | AsyncGroup) -> list[AsyncGroup]:
23862391
from zarr.core.group import AsyncGroup, GroupMetadata
23872392

2388-
if "/" in node.store_path.path:
2389-
required_parts = node.store_path.path.split("/")[:-1]
2390-
else:
2391-
required_parts = []
2393+
required_parts = node.store_path.path.split("/")[:-1]
23922394
parents = [
2395+
# the root group
23932396
AsyncGroup(
23942397
metadata=GroupMetadata(zarr_format=node.metadata.zarr_format),
23952398
store_path=StorePath(store=node.store_path.store, path=""),

src/zarr/core/group.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,9 @@ def __setitem__(self, key: str, value: Any) -> None:
836836
"""__setitem__ is not supported in v3"""
837837
raise NotImplementedError
838838

839+
def __repr__(self) -> str:
840+
return f"<Group {self.store_path}>"
841+
839842
async def update_attributes_async(self, new_attributes: dict[str, Any]) -> Group:
840843
new_metadata = replace(self.metadata, attributes=new_attributes)
841844

tests/v3/test_group.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ def test_group_create(store: Store, exists_ok: bool, zarr_format: ZarrFormat) ->
237237

238238
if not exists_ok:
239239
with pytest.raises(ContainsGroupError):
240-
group = Group.from_store(
241-
store, attributes=attributes, exists_ok=exists_ok, zarr_format=zarr_format
242-
)
240+
_ = Group.from_store(store, exists_ok=exists_ok, zarr_format=zarr_format)
243241

244242

245243
def test_group_open(store: Store, zarr_format: ZarrFormat, exists_ok: bool) -> None:

0 commit comments

Comments
 (0)