Skip to content

Commit 15c5103

Browse files
committed
fix __array__
1 parent 8454d7b commit 15c5103

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/zarr/core/array.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2218,8 +2218,10 @@ def __array__(
22182218
raise ValueError(msg)
22192219

22202220
arr_np = self[...]
2221+
if self.ndim==0:
2222+
arr_np = np.array(arr_np)
22212223

2222-
if dtype is not None and hasattr(arr_np, "astype"):
2224+
if dtype is not None:
22232225
arr_np = arr_np.astype(dtype)
22242226

22252227
return arr_np

src/zarr/core/buffer/core.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ def __setitem__(self, key: slice, value: Any) -> None:
138138
raise IndexError("Invalid index for scalar")
139139
self._value = value
140140

141-
def __array__(self) -> npt.NDArray[Any]:
142-
return np.array(self._value)
141+
def __array__(self, dtype: npt.DTypeLike | None = None, copy: bool | None = None
142+
) -> npt.NDArray[Any]:
143+
return np.array(self._value, dtype=dtype, copy=copy)
143144

144145
def reshape(
145146
self, shape: tuple[int, ...] | Literal[-1], *, order: Literal["A", "C", "F"] = "C"

0 commit comments

Comments
 (0)