Skip to content

Commit

Permalink
Remove unused fill value in LazyZarrArray
Browse files Browse the repository at this point in the history
Rename `lazy_empty` to `lazy_zarr_array`
Make param order more consistent
  • Loading branch information
tomwhite committed Mar 5, 2024
1 parent 59405ab commit b59e281
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
6 changes: 3 additions & 3 deletions cubed/primitive/blockwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
numpy_array_to_backend_array,
)
from cubed.runtime.types import CubedPipeline
from cubed.storage.zarr import T_ZarrArray, lazy_empty
from cubed.storage.zarr import T_ZarrArray, lazy_zarr_array
from cubed.types import T_Chunks, T_DType, T_Shape, T_Store
from cubed.utils import chunk_memory, get_item, map_nested, split_into, to_chunksize
from cubed.vendor.dask.array.core import normalize_chunks
Expand Down Expand Up @@ -279,8 +279,8 @@ def general_blockwise(
if isinstance(target_store, zarr.Array):
target_array = target_store
else:
target_array = lazy_empty(
shape, dtype=dtype, chunks=chunksize, store=target_store, path=target_path
target_array = lazy_zarr_array(
target_store, shape, dtype, chunks=chunksize, path=target_path
)

func_kwargs = extra_func_kwargs or {}
Expand Down
16 changes: 3 additions & 13 deletions cubed/primitive/rechunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from cubed.primitive.types import CubedArrayProxy, CubedCopySpec, PrimitiveOperation
from cubed.runtime.types import CubedPipeline
from cubed.storage.zarr import T_ZarrArray, lazy_empty
from cubed.storage.zarr import T_ZarrArray, lazy_zarr_array
from cubed.types import T_RegularChunks, T_Shape, T_Store
from cubed.vendor.rechunker.algorithm import rechunking_plan

Expand Down Expand Up @@ -125,25 +125,15 @@ def _setup_array_rechunk(
int_chunks = tuple(int(x) for x in int_chunks)
write_chunks = tuple(int(x) for x in write_chunks)

target_array = lazy_empty(
shape,
dtype=dtype,
chunks=target_chunks,
store=target_store,
)
target_array = lazy_zarr_array(target_store, shape, dtype, chunks=target_chunks)

if read_chunks == write_chunks:
int_array = None
else:
# do intermediate store
if temp_store is None:
raise ValueError("A temporary store location must be provided.")
int_array = lazy_empty(
shape,
dtype=dtype,
chunks=int_chunks,
store=temp_store,
)
int_array = lazy_zarr_array(temp_store, shape, dtype, chunks=int_chunks)

read_proxy = CubedArrayProxy(source_array, read_chunks)
int_proxy = CubedArrayProxy(int_array, int_chunks)
Expand Down
14 changes: 5 additions & 9 deletions cubed/storage/zarr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional, Union
from typing import Optional, Union

import zarr

Expand All @@ -15,12 +15,11 @@ class LazyZarrArray:

def __init__(
self,
store: T_Store,
shape: T_Shape,
dtype: T_DType,
chunks: T_RegularChunks,
store: T_Store,
path: Optional[str] = None,
fill_value: Any = None,
**kwargs,
):
"""Create a Zarr array lazily in memory."""
Expand All @@ -35,7 +34,6 @@ def __init__(

self.store = store
self.path = path
self.fill_value = fill_value
self.kwargs = kwargs

def create(self, mode: str = "w-") -> zarr.Array:
Expand All @@ -57,7 +55,6 @@ def create(self, mode: str = "w-") -> zarr.Array:
dtype=self.dtype,
chunks=self.chunks,
path=self.path,
fill_value=self.fill_value,
**self.kwargs,
)
return target
Expand All @@ -84,16 +81,15 @@ def __repr__(self) -> str:
T_ZarrArray = Union[zarr.Array, LazyZarrArray]


def lazy_empty(
def lazy_zarr_array(
store: T_Store,
shape: T_Shape,
*,
dtype: T_DType,
chunks: T_RegularChunks,
store: T_Store,
path: Optional[str] = None,
**kwargs,
) -> LazyZarrArray:
return LazyZarrArray(shape, dtype, chunks, store, path=path, **kwargs)
return LazyZarrArray(store, shape, dtype, chunks, path=path, **kwargs)


def open_if_lazy_zarr_array(array: T_ZarrArray) -> zarr.Array:
Expand Down
6 changes: 3 additions & 3 deletions cubed/tests/storage/test_zarr.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pytest

from cubed.storage.zarr import lazy_empty
from cubed.storage.zarr import lazy_zarr_array


def test_lazy_empty(tmp_path):
def test_lazy_zarr_array(tmp_path):
zarr_path = tmp_path / "lazy.zarr"
arr = lazy_empty((3, 3), dtype=int, chunks=(2, 2), store=zarr_path)
arr = lazy_zarr_array(zarr_path, shape=(3, 3), dtype=int, chunks=(2, 2))

assert not zarr_path.exists()
with pytest.raises(ValueError):
Expand Down

0 comments on commit b59e281

Please sign in to comment.