Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
brokkoli71 committed Jan 29, 2025
1 parent a93ce00 commit 805a8df
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/zarr/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,7 @@ def __array__(
raise ValueError(msg)

arr_np = self[...]
if self.ndim==0:
if self.ndim == 0:
arr_np = np.array(arr_np)

if dtype is not None:
Expand Down
5 changes: 3 additions & 2 deletions src/zarr/core/buffer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ def __setitem__(self, key: slice, value: Any) -> None:
raise IndexError("Invalid index for scalar")
self._value = value

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

def reshape(
Expand Down
5 changes: 3 additions & 2 deletions tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
chunks_initialized,
create_array,
)
from zarr.core.buffer import default_buffer_prototype, NDArrayLike
from zarr.core.buffer import NDArrayLike, default_buffer_prototype
from zarr.core.buffer.core import ScalarWrapper
from zarr.core.buffer.cpu import NDBuffer
from zarr.core.chunk_grids import _auto_partition
Expand Down Expand Up @@ -1257,6 +1257,7 @@ async def test_create_array_v2_no_shards(store: MemoryStore) -> None:
zarr_format=2,
)


@pytest.mark.parametrize("value", [1, 1.4, "a", b"a", np.array(1)])
def test_scalar_array(value: Any) -> None:
arr = zarr.array(value)
Expand All @@ -1282,7 +1283,7 @@ def test_scalar_array(value: Any) -> None:
assert x / 2 == value / 2
assert x // 2 == value // 2
assert x % 2 == value % 2
assert x ** 2 == value ** 2
assert x**2 == value**2
assert x == value
assert x != value + 1
assert bool(x) == bool(value)
Expand Down

0 comments on commit 805a8df

Please sign in to comment.