Skip to content

Commit 6dc00e1

Browse files
authored
Remove Zarr pin (#667)
* Remove Zarr pin * Update type hints for Zarr Python v3 * Escape pip package spec
1 parent 08c183d commit 6dc00e1

File tree

6 files changed

+18
-17
lines changed

6 files changed

+18
-17
lines changed

.github/workflows/zarr-v3-tests.yml renamed to .github/workflows/zarr-v2-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Zarr v3 Tests
1+
name: Zarr v2 Tests
22

33
on:
44
push:
@@ -44,7 +44,7 @@ jobs:
4444
- name: Install
4545
run: |
4646
python -m pip install -e .[test,lithops]
47-
python -m pip install -U git+https://github.com/zarr-developers/zarr-python.git
47+
python -m pip install -U 'zarr<3'
4848
4949
- name: Run tests
5050
env:

cubed/primitive/blockwise.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
numpy_array_to_backend_array,
1717
)
1818
from cubed.runtime.types import CubedPipeline
19-
from cubed.storage.zarr import T_ZarrArray, lazy_zarr_array
19+
from cubed.storage.zarr import LazyZarrArray, T_ZarrArray, lazy_zarr_array
2020
from cubed.types import T_Chunks, T_DType, T_Shape, T_Store
2121
from cubed.utils import array_memory, chunk_memory, get_item, map_nested
2222
from cubed.utils import numblocks as compute_numblocks
@@ -321,7 +321,7 @@ def general_blockwise(
321321

322322
write_proxies = []
323323
output_chunk_memory = 0
324-
target_array = []
324+
target_arrays = []
325325

326326
numblocks0 = None
327327
for i, target_store in enumerate(target_stores):
@@ -335,6 +335,7 @@ def general_blockwise(
335335
raise ValueError(
336336
f"All outputs must have matching number of blocks in each dimension. Chunks specified: {chunkss}"
337337
)
338+
ta: Union[zarr.Array, LazyZarrArray]
338339
if isinstance(target_store, zarr.Array):
339340
ta = target_store
340341
else:
@@ -347,7 +348,7 @@ def general_blockwise(
347348
storage_options=storage_options,
348349
compressor=compressor,
349350
)
350-
target_array.append(ta)
351+
target_arrays.append(ta)
351352

352353
write_proxies.append(CubedArrayProxy(ta, chunksize))
353354

@@ -356,9 +357,6 @@ def general_blockwise(
356357
output_chunk_memory, array_memory(dtypes[i], chunksize) * 2
357358
)
358359

359-
if len(target_array) == 1:
360-
target_array = target_array[0]
361-
362360
spec = BlockwiseSpec(
363361
key_function,
364362
func_with_kwargs,
@@ -404,7 +402,7 @@ def general_blockwise(
404402
return PrimitiveOperation(
405403
pipeline=pipeline,
406404
source_array_names=array_names,
407-
target_array=target_array,
405+
target_array=target_arrays[0] if len(target_arrays) == 1 else target_arrays,
408406
projected_mem=projected_mem,
409407
allowed_mem=allowed_mem,
410408
reserved_mem=reserved_mem,

cubed/primitive/rechunk.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import itertools
22
import math
33
from math import ceil, prod
4-
from typing import Any, Dict, Iterable, Iterator, List, Optional, Sequence, Tuple
4+
from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple
55

66
import numpy as np
77

@@ -68,10 +68,9 @@ def rechunk(
6868
storage_options=storage_options,
6969
)
7070

71-
intermediate = int_proxy.array
7271
target = write_proxy.array
7372

74-
if intermediate is None:
73+
if int_proxy is None:
7574
copy_spec = CubedCopySpec(read_proxy, write_proxy)
7675
num_tasks = total_chunks(write_proxy.array.shape, write_proxy.chunks)
7776
return [
@@ -88,6 +87,7 @@ def rechunk(
8887

8988
else:
9089
# break spec into two if there's an intermediate
90+
intermediate = int_proxy.array
9191
copy_spec1 = CubedCopySpec(read_proxy, int_proxy)
9292
num_tasks = total_chunks(copy_spec1.write.array.shape, copy_spec1.write.chunks)
9393
op1 = spec_to_primitive_op(
@@ -123,7 +123,7 @@ def _setup_array_rechunk(
123123
target_store: T_Store,
124124
temp_store: Optional[T_Store] = None,
125125
storage_options: Optional[Dict[str, Any]] = None,
126-
) -> Tuple[CubedArrayProxy, CubedArrayProxy, CubedArrayProxy]:
126+
) -> Tuple[CubedArrayProxy, Optional[CubedArrayProxy], CubedArrayProxy]:
127127
shape = source_array.shape
128128
source_chunks = source_array.chunks
129129
dtype = source_array.dtype
@@ -162,7 +162,9 @@ def _setup_array_rechunk(
162162
)
163163

164164
read_proxy = CubedArrayProxy(source_array, read_chunks)
165-
int_proxy = CubedArrayProxy(int_array, int_chunks)
165+
int_proxy = (
166+
CubedArrayProxy(int_array, int_chunks) if int_array is not None else None
167+
)
166168
write_proxy = CubedArrayProxy(target_array, write_chunks)
167169
return read_proxy, int_proxy, write_proxy
168170

@@ -200,7 +202,7 @@ def __iter__(self):
200202
return chunk_keys(self.shape, self.chunks)
201203

202204

203-
def copy_read_to_write(chunk_key: Sequence[slice], *, config: CubedCopySpec) -> None:
205+
def copy_read_to_write(chunk_key: Tuple[slice], *, config: CubedCopySpec) -> None:
204206
# workaround limitation of lithops.utils.verify_args
205207
if isinstance(chunk_key, list):
206208
chunk_key = tuple(chunk_key)

cubed/storage/backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def open_backend_array(
3333
storage_name = backend_storage_name()
3434

3535
if storage_name == "zarr-python":
36-
from cubed.storage.backends.zarr_python import open_zarr_array
36+
from cubed.storage.backends.zarr_python import open_zarr_array # type: ignore
3737

3838
open_func = open_zarr_array
3939

cubed/storage/backends/zarr_python.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# type: ignore # Zarr Python v2 types are different to v3
12
from typing import Optional, Union
23

34
import zarr

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dependencies = [
3636
"psutil",
3737
"tenacity",
3838
"toolz",
39-
"zarr < 3",
39+
"zarr",
4040
]
4141

4242
[project.optional-dependencies]

0 commit comments

Comments
 (0)