Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Nov 8, 2024
1 parent cdb1672 commit 035f53a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
16 changes: 11 additions & 5 deletions src/zarr/core/_info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import dataclasses
import textwrap
from typing import Literal
from typing import Any, Literal

import numcodecs.abc
import numpy as np

from zarr.abc.codec import Codec
from zarr.core.metadata.v3 import DataType


@dataclasses.dataclass(kw_only=True)
Expand Down Expand Up @@ -92,15 +98,15 @@ class ArrayInfo:

_type: Literal["Array"] = "Array"
_zarr_format: Literal[2, 3]
_data_type: str
_data_type: np.dtype[Any] | DataType
_shape: tuple[int, ...]
_chunk_shape: tuple[int, ...] | None = None
_order: Literal["C", "F"]
_read_only: bool
_store_type: str
_compressor: str | None = None
_filters: list[str] | None = None
_codecs: str | None = None
_compressor: numcodecs.abc.Codec | None = None
_filters: tuple[numcodecs.abc.Codec, ...] | None = None
_codecs: tuple[Codec, ...] | None = None
_count_bytes: int | None = None
_count_bytes_stored: int | None = None
_count_chunks_initialized: int | None = None
Expand Down
14 changes: 7 additions & 7 deletions src/zarr/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,18 +1365,18 @@ def _info(self, extra: dict[str, int] | None = None) -> Any:
if self.metadata.zarr_format == 2:
assert isinstance(self.metadata, ArrayV2Metadata)
if self.metadata.compressor is not None:
kwargs["compressor"] = str(self.metadata.compressor)
kwargs["_compressor"] = self.metadata.compressor
if self.metadata.filters is not None:
kwargs["filters"] = str(self.metadata.filters)
kwargs["data_type"] = str(self.metadata.dtype)
kwargs["chunk_shape"] = self.metadata.chunks
kwargs["_filters"] = self.metadata.filters
kwargs["_data_type"] = self.metadata.dtype
kwargs["_chunk_shape"] = self.metadata.chunks
else:
kwargs["codecs"] = str(self.metadata.codecs)
kwargs["data_type"] = str(self.metadata.data_type)
kwargs["_codecs"] = self.metadata.codecs
kwargs["_data_type"] = self.metadata.data_type
# just regular?
chunk_grid = self.metadata.chunk_grid
if isinstance(chunk_grid, RegularChunkGrid):
kwargs["chunk_shape"] = chunk_grid.chunk_shape
kwargs["_chunk_shape"] = chunk_grid.chunk_shape
else:
raise NotImplementedError(
"'info' is not yet implemented for chunk grids of type {type(self.metadata.chunk_grid)}"
Expand Down
7 changes: 4 additions & 3 deletions tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from zarr.core.common import JSON, MemoryOrder, ZarrFormat
from zarr.core.group import AsyncGroup
from zarr.core.indexing import ceildiv
from zarr.core.metadata.v3 import DataType
from zarr.core.sync import sync
from zarr.errors import ContainsArrayError, ContainsGroupError
from zarr.storage import LocalStore, MemoryStore
Expand Down Expand Up @@ -425,7 +426,7 @@ def test_info_v2(self) -> None:
result = arr.info
expected = ArrayInfo(
_zarr_format=2,
_data_type="float64",
_data_type=np.dtype("float64"),
_shape=(4, 4),
_chunk_shape=(2, 2),
_order="C",
Expand All @@ -440,13 +441,13 @@ def test_info_v3(self) -> None:
result = arr.info
expected = ArrayInfo(
_zarr_format=3,
_data_type="DataType.float64",
_data_type=DataType.parse("float64"),
_shape=(4, 4),
_chunk_shape=(2, 2),
_order="C",
_read_only=False,
_store_type="MemoryStore",
_codecs="[BytesCodec(endian=<Endian.little: 'little'>)]",
_codecs=(BytesCodec(),),
_count_bytes=128,
)
assert result == expected
Expand Down
22 changes: 11 additions & 11 deletions tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -1356,22 +1356,22 @@ def test_info(self):

result = A.info
expected = GroupInfo(
name="A",
read_only=False,
store_type="MemoryStore",
zarr_format=3,
_name="A",
_read_only=False,
_store_type="MemoryStore",
_zarr_format=3,
)
assert result == expected

result = A.info_complete()
expected = GroupInfo(
name="A",
read_only=False,
store_type="MemoryStore",
zarr_format=3,
count_members=3,
count_arrays=2,
count_groups=1,
_name="A",
_read_only=False,
_store_type="MemoryStore",
_zarr_format=3,
_count_members=3,
_count_arrays=2,
_count_groups=1,
)
assert result == expected

Expand Down

0 comments on commit 035f53a

Please sign in to comment.