Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions changes/3628.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid reading lazy arrays or on device arrays twice when comparing them to 0 during the writing process.
6 changes: 6 additions & 0 deletions src/zarr/core/codec_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,12 @@ async def _read_key(
if chunk_array is None:
chunk_array_batch.append(None) # type: ignore[unreachable]
else:
# The operation array_equal operation below effectively will force the array
# into memory.
# if the result is useful, we want to avoid reading it twice
# from a potentially lazy operation. So we cache it here.
# If the result is not useful, we leave it for the garbage collector.
chunk_array._data = chunk_array.as_numpy_array()
if not chunk_spec.config.write_empty_chunks and chunk_array.all_equal(
fill_value_or_default(chunk_spec)
):
Expand Down
Loading