Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 54b3d44

Browse filesBrowse files
authored
Avoid memory copy in local store write (#2944)
* Avoid memory copy in local store write
1 parent 9e8b50a commit 54b3d44
Copy full SHA for 54b3d44

File tree

2 files changed

+5
-2
lines changed
Filter options

2 files changed

+5
-2
lines changed

‎changes/2944.misc.rst

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Avoid an unnecessary memory copy when writing Zarr to a local file

‎src/zarr/storage/_local.py

Copy file name to clipboardExpand all lines: src/zarr/storage/_local.py
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,17 @@ def _put(
5151
if start is not None:
5252
with path.open("r+b") as f:
5353
f.seek(start)
54-
f.write(value.as_numpy_array().tobytes())
54+
# write takes any object supporting the buffer protocol
55+
f.write(value.as_numpy_array()) # type: ignore[arg-type]
5556
return None
5657
else:
57-
view = memoryview(value.as_numpy_array().tobytes())
58+
view = memoryview(value.as_numpy_array()) # type: ignore[arg-type]
5859
if exclusive:
5960
mode = "xb"
6061
else:
6162
mode = "wb"
6263
with path.open(mode=mode) as f:
64+
# write takes any object supporting the buffer protocol
6365
return f.write(view)
6466

6567

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.