Skip to content

Commit

Permalink
Rename 'grow' to 'extend'.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielballan committed Oct 31, 2024
1 parent 4c23297 commit a5d18dd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
26 changes: 20 additions & 6 deletions tiled/adapters/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,28 @@ async def patch(
self,
data: NDArray[Any],
slice: Tuple[slice | int, ...],
grow: bool = False,
extend: bool = False,
) -> Tuple[Tuple[int, ...], Tuple[Tuple[int, ...], ...]]:
"""
Write data into a slice of the array, maybe growing it.
Write data into a slice of the array, maybe extending it.
If the specified slice does not fit into the array, and grow=True, the
array will be resize (grown, never shrunk) to fit it. The new shape is
returned.
If the specified slice does not fit into the array, and extend=True, the
array will be resized (expanded, never shrunk) to fit it.
Parameters
----------
data : array-like
slice :
Where to place the new data
extend : bool
If slice does not fit wholly within the shape of the existing array,
reshape (expand) it to fit if this is True.
Raises
------
ValueError :
If slice does not fit wholly with the shape of the existing array
and expand is False
"""
current_shape = self._array.shape
new_shape = list(current_shape)
Expand All @@ -201,7 +215,7 @@ async def patch(
new_shape[i] = max(new_shape[i], s.stop)
new_shape_tuple = tuple(new_shape)
if new_shape_tuple != current_shape:
if grow:
if extend:
# Resize the Zarr array to accommodate new data
self._array.resize(new_shape_tuple)
else:
Expand Down
8 changes: 4 additions & 4 deletions tiled/client/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def write_block(self, array, block, slice=...):
)
)

def patch(self, array: NDArray, slice: NDSlice, grow=False):
def patch(self, array: NDArray, slice: NDSlice, extend=False):
"""
Write data
Expand All @@ -189,13 +189,13 @@ def patch(self, array: NDArray, slice: NDSlice, grow=False):
The data to write
slice : NDSlice
Where to place this data in the array
grow : bool
Grow the array shape to fit the new slice, if necessary
extend : bool
Extend the array shape to fit the new slice, if necessary
"""
array_ = numpy.ascontiguousarray(array)
params = params_from_slice(slice)
params["shape"] = ",".join(map(str, array_.shape))
params["grow"] = bool(grow)
params["extend"] = bool(extend)
handle_error(
self.context.http_client.patch(
self.item["links"]["full"],
Expand Down
4 changes: 2 additions & 2 deletions tiled/server/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ async def patch_array_full(
request: Request,
slice=Depends(slice_),
shape=Depends(shape_param),
grow: bool = False,
extend: bool = False,
entry=SecureEntry(
scopes=["write:data"],
structure_families={StructureFamily.array},
Expand All @@ -1316,7 +1316,7 @@ async def patch_array_full(
media_type = request.headers["content-type"]
deserializer = deserialization_registry.dispatch("array", media_type)
data = await ensure_awaitable(deserializer, body, dtype, shape)
await ensure_awaitable(entry.patch, data, slice, grow)
await ensure_awaitable(entry.patch, data, slice, extend)
return json_or_msgpack(request, None)


Expand Down

0 comments on commit a5d18dd

Please sign in to comment.