Skip to content

Commit 58864cd

Browse files
committed
fix: use numbers.Number
1 parent 85faffb commit 58864cd

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/zarr/core/buffer/cpu.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import numbers
34
from typing import (
45
TYPE_CHECKING,
56
Any,
@@ -155,7 +156,10 @@ def create(
155156
fill_value: Any | None = None,
156157
) -> Self:
157158
# np.zeros is much faster than np.full, and therefore using it when possible is better.
158-
if fill_value is None or (np.isscalar(fill_value) and fill_value == 0):
159+
# See https://numpy.org/doc/stable/reference/generated/numpy.isscalar.html#numpy-isscalar
160+
# notes for why we use `numbers.Number`.
161+
# Tehcnically `numbers.Number` need not support __eq__ hence the `ignore`.
162+
if fill_value is None or (isinstance(fill_value, numbers.Number) and fill_value == 0): # type: ignore[comparison-overlap]
159163
return cls(np.zeros(shape=tuple(shape), dtype=dtype, order=order))
160164
else:
161165
return cls(np.full(shape=tuple(shape), fill_value=fill_value, dtype=dtype, order=order))

0 commit comments

Comments
 (0)