File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3+ import numbers
34from 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 ))
You can’t perform that action at this time.
0 commit comments