Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Oct 10, 2024
1 parent 96b274c commit c9229d1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 40 deletions.
5 changes: 4 additions & 1 deletion src/zarr/api/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ async def consolidate_metadata(
By default, the root node is used so all the metadata in the
store is consolidated.
zarr_format : {2, 3, None}, optional
The zarr format of the hierarchy. By default the zarr format
is inferred.
Returns
-------
Expand Down Expand Up @@ -662,7 +665,7 @@ async def open_group(
to users. Use `numpy.empty(())` by default.
attributes : dict
A dictionary of JSON-serializable values with user-defined attributes.
use_consolidated : bool or str, default None
use_consolidated : bool or str, default None
Whether to use consolidated metadata.
By default, consolidated metadata is used if it's present in the
Expand Down
11 changes: 4 additions & 7 deletions src/zarr/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@
ArrayV3MetadataDict,
T_ArrayMetadata,
)
from zarr.core.metadata.v3 import parse_node_type_array
from zarr.core.sync import collect_aiterator, sync
from zarr.errors import MetadataValidationError, NodeTypeValidationError
from zarr.errors import MetadataValidationError
from zarr.registry import get_pipeline_class
from zarr.storage import StoreLike, make_store_path
from zarr.storage.common import StorePath, ensure_no_existing_node
Expand Down Expand Up @@ -166,12 +167,8 @@ async def get_array_metadata(
assert zarr_json_bytes is not None
metadata_dict = json.loads(zarr_json_bytes.to_bytes())

node_type = metadata_dict.get("node_type")
if node_type != "array":
# This KeyError is load bearing for `open`. That currently tries
# to open the node as an `array` and then falls back to opening
# as a group.
raise NodeTypeValidationError("node_type", "array", node_type)
parse_node_type_array(metadata_dict.get("node_type"))

return metadata_dict


Expand Down
32 changes: 0 additions & 32 deletions src/zarr/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import logging
from collections import defaultdict
from dataclasses import asdict, dataclass, field, fields, replace
from enum import Enum
from typing import TYPE_CHECKING, Literal, TypeVar, assert_never, cast, overload

import numcodecs.abc
import numpy as np
import numpy.typing as npt
from typing_extensions import deprecated
Expand Down Expand Up @@ -99,36 +97,6 @@ def _parse_async_node(
raise TypeError(f"Unknown node type, got {type(node)}")


def _json_convert(o: object) -> Any:
if isinstance(o, np.dtype):
return str(o)
if np.isscalar(o):
out: Any
if hasattr(o, "dtype") and o.dtype.kind == "M" and hasattr(o, "view"):
# https://github.com/zarr-developers/zarr-python/issues/2119
# `.item()` on a datetime type might or might not return an
# integer, depending on the value.
# Explicitly cast to an int first, and then grab .item()
out = o.view("i8").item()
else:
# convert numpy scalar to python type, and pass
# python types through
out = getattr(o, "item", lambda: o)()
if isinstance(out, complex):
# python complex types are not JSON serializable, so we use the
# serialization defined in the zarr v3 spec
return [out.real, out.imag]
return out
if isinstance(o, Enum):
return o.name
# this serializes numcodecs compressors
# todo: implement to_dict for codecs
elif isinstance(o, numcodecs.abc.Codec):
config: dict[str, Any] = o.get_config()
return config
raise TypeError


@dataclass(frozen=True)
class ConsolidatedMetadata:
"""
Expand Down

0 comments on commit c9229d1

Please sign in to comment.