Skip to content
Merged
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/2944.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid an unnecessary memory copy when writing Zarr to a local file
6 changes: 4 additions & 2 deletions src/zarr/storage/_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ def _put(
if start is not None:
with path.open("r+b") as f:
f.seek(start)
f.write(value.as_numpy_array().tobytes())
# write takes any object supporting the buffer protocol
f.write(value.as_numpy_array()) # type: ignore[arg-type]
return None
else:
view = memoryview(value.as_numpy_array().tobytes())
view = memoryview(value.as_numpy_array()) # type: ignore[arg-type]
if exclusive:
mode = "xb"
else:
mode = "wb"
with path.open(mode=mode) as f:
# write takes any object supporting the buffer protocol
return f.write(view)


Expand Down