Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clean up parents
  • Loading branch information
jhamman committed Sep 30, 2024
commit 77f293882eca6b4193a5d7645fcc0058d12934a0
11 changes: 7 additions & 4 deletions src/zarr/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
from asyncio import gather
from dataclasses import dataclass, field, replace
from logging import getLogger
from typing import TYPE_CHECKING, Any, Literal, cast

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

logger = getLogger(__name__)


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

logger.debug("Ensure parents: %s", parents)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to keep this?


for parent in parents:
awaitables.extend(
[
Expand Down Expand Up @@ -2385,11 +2390,9 @@ def chunks_initialized(array: Array | AsyncArray) -> tuple[str, ...]:
def _build_parents(node: AsyncArray | AsyncGroup) -> list[AsyncGroup]:
from zarr.core.group import AsyncGroup, GroupMetadata

if "/" in node.store_path.path:
required_parts = node.store_path.path.split("/")[:-1]
else:
required_parts = []
required_parts = node.store_path.path.split("/")[:-1]
parents = [
# the root group
AsyncGroup(
metadata=GroupMetadata(zarr_format=node.metadata.zarr_format),
store_path=StorePath(store=node.store_path.store, path=""),
Expand Down
3 changes: 3 additions & 0 deletions src/zarr/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,9 @@ def __setitem__(self, key: str, value: Any) -> None:
"""__setitem__ is not supported in v3"""
raise NotImplementedError

def __repr__(self) -> str:
return f"<Group {self.store_path}>"

async def update_attributes_async(self, new_attributes: dict[str, Any]) -> Group:
new_metadata = replace(self.metadata, attributes=new_attributes)

Expand Down
4 changes: 1 addition & 3 deletions tests/v3/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,7 @@ def test_group_create(store: Store, exists_ok: bool, zarr_format: ZarrFormat) ->

if not exists_ok:
with pytest.raises(ContainsGroupError):
group = Group.from_store(
store, attributes=attributes, exists_ok=exists_ok, zarr_format=zarr_format
)
_ = Group.from_store(store, exists_ok=exists_ok, zarr_format=zarr_format)


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