Skip to content

Commit a1deda6

Browse files
committed
Merge branch 'main' of https://github.com/zarr-developers/zarr-python into feat/fixed-length-strings
2 parents 4e2a157 + f674236 commit a1deda6

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

changes/3082.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use :py:func:`numpy.zeros` instead of :py:func:`np.full` for a performance speedup when creating a `zarr.core.buffer.NDBuffer` with `fill_value=0`.

src/zarr/core/buffer/cpu.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ def create(
154154
order: Literal["C", "F"] = "C",
155155
fill_value: Any | None = None,
156156
) -> Self:
157-
if fill_value is None:
157+
# np.zeros is much faster than np.full, and therefore using it when possible is better.
158+
if fill_value is None or (isinstance(fill_value, int) and fill_value == 0):
158159
return cls(np.zeros(shape=tuple(shape), dtype=dtype, order=order))
159160
else:
160161
return cls(np.full(shape=tuple(shape), fill_value=fill_value, dtype=dtype, order=order))

0 commit comments

Comments
 (0)