Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
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
11 changes: 9 additions & 2 deletions virtualizarr/manifests/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@

import numpy as np
import xarray as xr
from zarr.core.metadata.v3 import ArrayV3Metadata, RegularChunkGrid
from zarr.core.metadata.v3 import ArrayV3Metadata

try:
from zarr.core.metadata.v3 import RegularChunkGridMetadata # zarr-python>3.1.6
except ImportError:
from zarr.core.metadata.v3 import (
RegularChunkGrid as RegularChunkGridMetadata, # zarr-python<=3.1.6
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we should actually look for specific versions of zarr-python instead of the blind try...except?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Zarr-Python uses hatch-vcs, which builds versions from git tags. If a user installs from a git source that does not have the tags fetched, the version can display as a low number despite being based on the most recent commits to main, which breaks the code with an obscure error message. This try...except leads to informative error messages by describing exactly what is needed rather than implicitly relying on the version.


import virtualizarr.manifests.utils as utils
from virtualizarr.manifests.array_api import (
Expand Down Expand Up @@ -50,7 +57,7 @@ def __init__(
# try unpacking the dict
_metadata = ArrayV3Metadata(**metadata)

if not isinstance(_metadata.chunk_grid, RegularChunkGrid):
if not isinstance(_metadata.chunk_grid, RegularChunkGridMetadata):
raise NotImplementedError(
f"Only RegularChunkGrid is currently supported for chunk size, but got type {type(_metadata.chunk_grid)}"
)
Expand Down
12 changes: 9 additions & 3 deletions virtualizarr/parsers/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
import zarr
from obspec_utils.registry import ObjectStoreRegistry
from zarr.api.asynchronous import open_group as open_group_async
from zarr.core.chunk_grids import RegularChunkGrid

try:
from zarr.core.metadata.v3 import RegularChunkGridMetadata # zarr-python>3.1.6
except ImportError:
from zarr.core.chunk_grids import (
RegularChunkGrid as RegularChunkGridMetadata, # zarr-python<=3.1.6
)
from zarr.core.metadata import ArrayV2Metadata, ArrayV3Metadata
from zarr.storage import ObjectStore

Expand Down Expand Up @@ -267,7 +273,7 @@ async def construct_manifest_array(
"""Construct a ManifestArray from a zarr array."""
array_v3_metadata = metadata_as_v3(zarr_array.metadata)

if not isinstance(array_v3_metadata.chunk_grid, RegularChunkGrid):
if not isinstance(array_v3_metadata.chunk_grid, RegularChunkGridMetadata):
raise NotImplementedError(
f"Only RegularChunkGrid is supported, but array {zarr_array.path} "
f"uses {type(array_v3_metadata.chunk_grid).__name__}."
Expand Down Expand Up @@ -387,7 +393,7 @@ async def build_chunk_manifest(
# chunk shape, which lives inside the ShardingCodec config). So this grid describes
# the number of shard files on disk, which is exactly what we want for the manifest.
chunk_grid_shape = determine_chunk_grid_shape(
metadata.shape, cast(RegularChunkGrid, metadata.chunk_grid).chunk_shape
metadata.shape, cast(RegularChunkGridMetadata, metadata.chunk_grid).chunk_shape
)
total_size = math.prod(chunk_grid_shape)

Expand Down
Loading