From f03c0268a04f797a9d7b9b6440660ab379e9b29c Mon Sep 17 00:00:00 2001 From: brokkoli71 Date: Wed, 12 Feb 2025 15:34:03 +0100 Subject: [PATCH] undo wrong code changes --- src/zarr/api/asynchronous.py | 2 +- src/zarr/api/synchronous.py | 3 +-- src/zarr/codecs/bytes.py | 4 ++-- src/zarr/core/array.py | 16 ++++++++-------- src/zarr/core/buffer/__init__.py | 2 ++ tests/test_api.py | 2 +- tests/test_array.py | 3 +-- tests/test_buffer.py | 3 +-- tests/test_codecs/test_codecs.py | 2 +- tests/test_codecs/test_sharding.py | 3 +-- 10 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/zarr/api/asynchronous.py b/src/zarr/api/asynchronous.py index 3bfd3aed47..74144bf819 100644 --- a/src/zarr/api/asynchronous.py +++ b/src/zarr/api/asynchronous.py @@ -11,7 +11,7 @@ from zarr.core.array import Array, AsyncArray, create_array, get_array_metadata from zarr.core.array_spec import ArrayConfig, ArrayConfigLike -from zarr.core.buffer.core import NDArrayLike +from zarr.core.buffer import NDArrayLike from zarr.core.common import ( JSON, AccessModeLiteral, diff --git a/src/zarr/api/synchronous.py b/src/zarr/api/synchronous.py index a9392a53f8..caed628618 100644 --- a/src/zarr/api/synchronous.py +++ b/src/zarr/api/synchronous.py @@ -26,8 +26,7 @@ ShardsLike, ) from zarr.core.array_spec import ArrayConfig, ArrayConfigLike - from zarr.core.buffer import NDArrayOrScalarLike - from zarr.core.buffer.core import NDArrayLike + from zarr.core.buffer import NDArrayLike, NDArrayOrScalarLike from zarr.core.chunk_key_encodings import ChunkKeyEncoding, ChunkKeyEncodingLike from zarr.core.common import ( JSON, diff --git a/src/zarr/codecs/bytes.py b/src/zarr/codecs/bytes.py index 5538ec15f8..78c7b22fbc 100644 --- a/src/zarr/codecs/bytes.py +++ b/src/zarr/codecs/bytes.py @@ -8,7 +8,7 @@ import numpy as np from zarr.abc.codec import ArrayBytesCodec -from zarr.core.buffer import Buffer, NDArrayOrScalarLike, NDBuffer +from zarr.core.buffer import Buffer, NDArrayLike, NDBuffer from zarr.core.common import JSON, parse_enum, parse_named_configuration from zarr.registry import register_codec @@ -81,7 +81,7 @@ async def _decode_single( dtype = np.dtype(f"|{chunk_spec.dtype.str[1:]}") as_array_like = chunk_bytes.as_array_like() - if isinstance(as_array_like, NDArrayOrScalarLike): + if isinstance(as_array_like, NDArrayLike): as_nd_array_like = as_array_like else: as_nd_array_like = np.asanyarray(as_array_like) diff --git a/src/zarr/core/array.py b/src/zarr/core/array.py index 853c8432d7..17001134f1 100644 --- a/src/zarr/core/array.py +++ b/src/zarr/core/array.py @@ -34,11 +34,11 @@ from zarr.core.attributes import Attributes from zarr.core.buffer import ( BufferPrototype, + NDArrayLike, NDArrayOrScalarLike, NDBuffer, default_buffer_prototype, ) -from zarr.core.buffer.core import NDArrayLike from zarr.core.chunk_grids import RegularChunkGrid, _auto_partition, normalize_chunks from zarr.core.chunk_key_encodings import ( ChunkKeyEncoding, @@ -1397,7 +1397,7 @@ async def _set_selection( # ), f"shape of value doesn't match indexer shape. Expected {indexer.shape}, got {value.shape}" if not hasattr(value, "dtype") or value.dtype.name != self.metadata.dtype.name: if hasattr(value, "astype"): - # Handle things that are already NDArrayOrScalarLike more efficiently + # Handle things that are already NDArrayLike more efficiently value = value.astype(dtype=self.metadata.dtype, order="A") else: value = np.array(value, dtype=self.metadata.dtype, order="A") @@ -2290,7 +2290,7 @@ def __getitem__(self, selection: Selection) -> NDArrayOrScalarLike: Returns ------- NDArrayOrScalarLike - An array-like containing the data for the requested region. + An array-like or scalar containing the data for the requested region. Examples -------- @@ -2555,7 +2555,7 @@ def get_basic_selection( Returns ------- NDArrayOrScalarLike - An array-like containing the data for the requested region. + An array-like or scalar containing the data for the requested region. Examples -------- @@ -2779,7 +2779,7 @@ def get_orthogonal_selection( Returns ------- NDArrayOrScalarLike - An array-like containing the data for the requested selection. + An array-like or scalar containing the data for the requested selection. Examples -------- @@ -3013,7 +3013,7 @@ def get_mask_selection( Returns ------- NDArrayOrScalarLike - An array-like containing the data for the requested selection. + An array-like or scalar containing the data for the requested selection. Examples -------- @@ -3173,7 +3173,7 @@ def get_coordinate_selection( Returns ------- NDArrayOrScalarLike - An array-like containing the data for the requested coordinate selection. + An array-like or scalar containing the data for the requested coordinate selection. Examples -------- @@ -3361,7 +3361,7 @@ def get_block_selection( Returns ------- NDArrayOrScalarLike - An array-like containing the data for the requested block selection. + An array-like or scalar containing the data for the requested block selection. Examples -------- diff --git a/src/zarr/core/buffer/__init__.py b/src/zarr/core/buffer/__init__.py index ecd4758907..639bcf3d95 100644 --- a/src/zarr/core/buffer/__init__.py +++ b/src/zarr/core/buffer/__init__.py @@ -2,6 +2,7 @@ ArrayLike, Buffer, BufferPrototype, + NDArrayLike, NDArrayOrScalarLike, NDBuffer, default_buffer_prototype, @@ -12,6 +13,7 @@ "ArrayLike", "Buffer", "BufferPrototype", + "NDArrayLike", "NDArrayOrScalarLike", "NDBuffer", "default_buffer_prototype", diff --git a/tests/test_api.py b/tests/test_api.py index 0e2dccd343..2cfed2c52a 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -23,7 +23,7 @@ save_array, save_group, ) -from zarr.core.buffer.core import NDArrayLike +from zarr.core.buffer import NDArrayLike from zarr.core.common import JSON, MemoryOrder, ZarrFormat from zarr.errors import MetadataValidationError from zarr.storage import MemoryStore diff --git a/tests/test_array.py b/tests/test_array.py index e1a51e288c..5a63941c0f 100644 --- a/tests/test_array.py +++ b/tests/test_array.py @@ -37,8 +37,7 @@ chunks_initialized, create_array, ) -from zarr.core.buffer import NDArrayOrScalarLike, default_buffer_prototype -from zarr.core.buffer.core import NDArrayLike +from zarr.core.buffer import NDArrayLike, NDArrayOrScalarLike, default_buffer_prototype from zarr.core.buffer.cpu import NDBuffer from zarr.core.chunk_grids import _auto_partition from zarr.core.common import JSON, MemoryOrder, ZarrFormat diff --git a/tests/test_buffer.py b/tests/test_buffer.py index 9e6ca85db9..33ac0266eb 100644 --- a/tests/test_buffer.py +++ b/tests/test_buffer.py @@ -11,8 +11,7 @@ from zarr.codecs.gzip import GzipCodec from zarr.codecs.transpose import TransposeCodec from zarr.codecs.zstd import ZstdCodec -from zarr.core.buffer import ArrayLike, BufferPrototype, cpu, gpu -from zarr.core.buffer.core import NDArrayLike +from zarr.core.buffer import ArrayLike, BufferPrototype, NDArrayLike, cpu, gpu from zarr.storage import MemoryStore, StorePath from zarr.testing.buffer import ( NDBufferUsingTestNDArrayLike, diff --git a/tests/test_codecs/test_codecs.py b/tests/test_codecs/test_codecs.py index e36a332440..b8122b4ac2 100644 --- a/tests/test_codecs/test_codecs.py +++ b/tests/test_codecs/test_codecs.py @@ -23,7 +23,7 @@ if TYPE_CHECKING: from zarr.abc.store import Store - from zarr.core.buffer.core import NDArrayLike + from zarr.core.buffer import NDArrayLike from zarr.core.common import MemoryOrder diff --git a/tests/test_codecs/test_sharding.py b/tests/test_codecs/test_sharding.py index b6f39d5ecc..403fd80e81 100644 --- a/tests/test_codecs/test_sharding.py +++ b/tests/test_codecs/test_sharding.py @@ -16,8 +16,7 @@ ShardingCodecIndexLocation, TransposeCodec, ) -from zarr.core.buffer import default_buffer_prototype -from zarr.core.buffer.core import NDArrayLike +from zarr.core.buffer import NDArrayLike, default_buffer_prototype from zarr.storage import StorePath from ..conftest import ArrayRequest