Skip to content

Commit f6765bc

Browse files
authored
Merge branch 'main' into feat/read-funcs
2 parents d95eba8 + ca46bab commit f6765bc

37 files changed

+258
-160
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ default_language_version:
77
python: python3
88
repos:
99
- repo: https://github.com/astral-sh/ruff-pre-commit
10-
rev: v0.7.1
10+
rev: v0.7.2
1111
hooks:
1212
- id: ruff
1313
args: ["--fix", "--show-fixes"]

pyproject.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,19 +269,25 @@ extend-exclude = [
269269
extend-select = [
270270
"ANN", # flake8-annotations
271271
"B", # flake8-bugbear
272+
"EXE", # flake8-executable
272273
"C4", # flake8-comprehensions
274+
"FA", # flake8-future-annotations
273275
"FLY", # flynt
274276
"FURB", # refurb
275277
"G", # flake8-logging-format
276278
"I", # isort
277279
"ISC", # flake8-implicit-str-concat
280+
"LOG", # flake8-logging
278281
"PERF", # Perflint
282+
"PIE", # flake8-pie
279283
"PGH", # pygrep-hooks
280284
"PT", # flake8-pytest-style
281285
"PYI", # flake8-pyi
282-
"RSE", # flake8-raise
283286
"RET", # flake8-return
287+
"RSE", # flake8-raise
284288
"RUF",
289+
"SIM", # flake8-simplify
290+
"SLOT", # flake8-slots
285291
"TCH", # flake8-type-checking
286292
"TRY", # tryceratops
287293
"UP", # pyupgrade
@@ -298,6 +304,7 @@ ignore = [
298304
"RET505",
299305
"RET506",
300306
"RUF005",
307+
"SIM108",
301308
"TRY003",
302309
"UP027", # deprecated
303310
"UP038", # https://github.com/astral-sh/ruff/issues/7871
@@ -319,7 +326,7 @@ ignore = [
319326
]
320327

321328
[tool.ruff.lint.extend-per-file-ignores]
322-
"tests/**" = ["ANN001", "ANN201"]
329+
"tests/**" = ["ANN001", "ANN201", "RUF029", "SIM117", "SIM300"]
323330

324331
[tool.mypy]
325332
python_version = "3.11"

src/zarr/abc/codec.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ def validate(self, *, shape: ChunkCoords, dtype: np.dtype[Any], chunk_grid: Chun
106106
chunk_grid : ChunkGrid
107107
The array chunk grid
108108
"""
109-
...
110109

111110
async def _decode_single(self, chunk_data: CodecOutput, chunk_spec: ArraySpec) -> CodecInput:
112111
raise NotImplementedError

src/zarr/abc/metadata.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,5 @@ def from_dict(cls, data: dict[str, JSON]) -> Self:
4242
"""
4343
Create an instance of the model from a dictionary
4444
"""
45-
...
4645

4746
return cls(**data)

src/zarr/abc/store.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ async def _set_many(self, values: Iterable[tuple[str, Buffer]]) -> None:
284284
Insert multiple (key, value) pairs into storage.
285285
"""
286286
await gather(*starmap(self.set, values))
287-
return
288287

289288
@property
290289
@abstractmethod
@@ -342,8 +341,8 @@ def list(self) -> AsyncGenerator[str, None]:
342341
@abstractmethod
343342
def list_prefix(self, prefix: str) -> AsyncGenerator[str, None]:
344343
"""
345-
Retrieve all keys in the store that begin with a given prefix. Keys are returned with the
346-
common leading prefix removed.
344+
Retrieve all keys in the store that begin with a given prefix. Keys are returned relative
345+
to the root of the store.
347346
348347
Parameters
349348
----------
@@ -371,6 +370,20 @@ def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
371370
"""
372371
...
373372

373+
async def delete_dir(self, prefix: str) -> None:
374+
"""
375+
Remove all keys and prefixes in the store that begin with a given prefix.
376+
"""
377+
if not self.supports_deletes:
378+
raise NotImplementedError
379+
if not self.supports_listing:
380+
raise NotImplementedError
381+
self._check_writable()
382+
if not prefix.endswith("/"):
383+
prefix += "/"
384+
async for key in self.list_prefix(prefix):
385+
await self.delete(key)
386+
374387
def close(self) -> None:
375388
"""Close the store."""
376389
self._is_open = False

src/zarr/api/asynchronous.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from zarr.abc.store import Store
1212
from zarr.core.array import Array, AsyncArray, get_array_metadata
13+
from zarr.core.buffer import NDArrayLike
1314
from zarr.core.common import (
1415
JSON,
1516
AccessModeLiteral,
@@ -31,7 +32,6 @@
3132
from collections.abc import Iterable
3233

3334
from zarr.abc.codec import Codec
34-
from zarr.core.buffer import NDArrayLike
3535
from zarr.core.chunk_key_encodings import ChunkKeyEncoding
3636

3737
# TODO: this type could use some more thought
@@ -434,6 +434,8 @@ async def save_array(
434434
_handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
435435
or _default_zarr_version()
436436
)
437+
if not isinstance(arr, NDArrayLike):
438+
raise TypeError("arr argument must be numpy or other NDArrayLike array")
437439

438440
mode = kwargs.pop("mode", None)
439441
store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options)
@@ -488,16 +490,26 @@ async def save_group(
488490
or _default_zarr_version()
489491
)
490492

493+
for arg in args:
494+
if not isinstance(arg, NDArrayLike):
495+
raise TypeError(
496+
"All arguments must be numpy or other NDArrayLike arrays (except store, path, storage_options, and zarr_format)"
497+
)
498+
for k, v in kwargs.items():
499+
if not isinstance(v, NDArrayLike):
500+
raise TypeError(f"Keyword argument '{k}' must be a numpy or other NDArrayLike array")
501+
491502
if len(args) == 0 and len(kwargs) == 0:
492503
raise ValueError("at least one array must be provided")
493504
aws = []
494505
for i, arr in enumerate(args):
506+
_path = f"{path}/arr_{i}" if path is not None else f"arr_{i}"
495507
aws.append(
496508
save_array(
497509
store,
498510
arr,
499511
zarr_format=zarr_format,
500-
path=f"{path}/arr_{i}",
512+
path=_path,
501513
storage_options=storage_options,
502514
)
503515
)
@@ -967,9 +979,8 @@ async def create(
967979
warnings.warn("meta_array is not yet implemented", RuntimeWarning, stacklevel=2)
968980

969981
mode = kwargs.pop("mode", None)
970-
if mode is None:
971-
if not isinstance(store, Store | StorePath):
972-
mode = "a"
982+
if mode is None and not isinstance(store, Store | StorePath):
983+
mode = "a"
973984

974985
store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options)
975986

src/zarr/codecs/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
from zarr.codecs.bytes import BytesCodec, Endian
1010
from zarr.codecs.crc32c_ import Crc32cCodec
1111
from zarr.codecs.gzip import GzipCodec
12-
from zarr.codecs.pipeline import BatchedCodecPipeline
1312
from zarr.codecs.sharding import ShardingCodec, ShardingCodecIndexLocation
1413
from zarr.codecs.transpose import TransposeCodec
1514
from zarr.codecs.vlen_utf8 import VLenBytesCodec, VLenUTF8Codec
1615
from zarr.codecs.zstd import ZstdCodec
1716
from zarr.core.metadata.v3 import DataType
1817

1918
__all__ = [
20-
"BatchedCodecPipeline",
2119
"BloscCname",
2220
"BloscCodec",
2321
"BloscShuffle",

src/zarr/codecs/gzip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
def parse_gzip_level(data: JSON) -> int:
2222
if not isinstance(data, (int)):
2323
raise TypeError(f"Expected int, got {type(data)}")
24-
if data not in range(0, 10):
24+
if data not in range(10):
2525
raise ValueError(
2626
f"Expected an integer from the inclusive range (0, 9). Got {data} instead."
2727
)

src/zarr/codecs/registry.py

Whitespace-only changes.

src/zarr/codecs/sharding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def create_empty(
252252
def __setitem__(self, chunk_coords: ChunkCoords, value: Buffer) -> None:
253253
chunk_start = len(self.buf)
254254
chunk_length = len(value)
255-
self.buf = self.buf + value
255+
self.buf += value
256256
self.index.set_chunk_slice(chunk_coords, slice(chunk_start, chunk_start + chunk_length))
257257

258258
def __delitem__(self, chunk_coords: ChunkCoords) -> None:

0 commit comments

Comments
 (0)