Skip to content

Commit c95780e

Browse files
pre-commit-ci[bot]floriankrb
authored andcommitted
allow using zarr2 for python 3.10, fix save_zarr code and test
1 parent 756b6b8 commit c95780e

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ dependencies = [
5959
"ruamel-yaml",
6060
"semantic-version",
6161
"tqdm",
62-
"zarr>=3.1.3",
62+
"zarr", # will use zarr3 for python >=3.11
6363
]
6464

6565
optional-dependencies.all = [

src/anemoi/datasets/data/misc.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ def initialize_zarr_store(root: Any, big_dataset: "Dataset") -> None:
664664
# Create or append to "dates" dataset.
665665
if "dates" not in root:
666666
full_length = len(big_dataset.dates)
667-
root.create_dataset("dates", data=np.array([], dtype="datetime64[s]"), chunks=(full_length,))
667+
root.create_dataset("dates", data=np.array([], dtype="datetime64[s]"), chunks=(full_length,), shape=(0,))
668668

669669
if "data" not in root:
670670
dims = (1, len(big_dataset.variables), ensembles, big_dataset.shape[-1])
@@ -681,12 +681,15 @@ def initialize_zarr_store(root: Any, big_dataset: "Dataset") -> None:
681681
k,
682682
data=v,
683683
compressor=None,
684+
shape=v.shape,
684685
)
685686

686687
# Create spatial coordinate datasets if missing.
687688
if "latitudes" not in root or "longitudes" not in root:
688-
root.create_dataset("latitudes", data=big_dataset.latitudes, compressor=None)
689-
root.create_dataset("longitudes", data=big_dataset.longitudes, compressor=None)
689+
root.create_dataset("latitudes", data=big_dataset.latitudes, compressor=None, shape=big_dataset.latitudes.shape)
690+
root.create_dataset(
691+
"longitudes", data=big_dataset.longitudes, compressor=None, shape=big_dataset.longitudes.shape
692+
)
690693
for k, v in big_dataset.metadata().items():
691694
if k not in root.attrs:
692695
root.attrs[k] = v

tests/create/utils/compare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def compare_dot_zattrs(a: dict, b: dict, path: str, errors: list) -> None:
161161
"description",
162162
"config_path",
163163
"total_size",
164-
"total_number_of_files", # these are expected to differ between zarr 2 and zarr 3
164+
"total_number_of_files", # these are expected to differ between zarr 2 and zarr 3
165165
]:
166166
if type(a[k]) is not type(b[k]):
167167
errors.append(f"❌ {path}.{k} : type differs {type(a[k])} != {type(b[k])}")

tests/test_data.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
VALUES = 10
4444

45+
true_zarr_open = zarr.open
46+
4547

4648
def mockup_open_zarr(func: Callable) -> Callable:
4749
"""Decorator to mock the open_zarr function.
@@ -237,6 +239,8 @@ def zarr_from_str(name: str, mode: str) -> zarr.Group:
237239
Zarr dataset.
238240
"""
239241
# Format: test-2021-2021-6h-o96-abcd-0
242+
if "/" in name:
243+
return true_zarr_open(name)
240244

241245
args = dict(
242246
test="test",

0 commit comments

Comments
 (0)