Skip to content

Commit d88ea61

Browse files
authored
Merge branch 'main' into fix/localstore-listdir
2 parents c8d7503 + f05413e commit d88ea61

38 files changed

+331
-233
lines changed

.github/workflows/releases.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
with:
5656
name: releases
5757
path: dist
58-
- uses: pypa/gh-action-pypi-publish@v1.10.3
58+
- uses: pypa/gh-action-pypi-publish@v1.11.0
5959
with:
6060
user: __token__
6161
password: ${{ secrets.pypi_password }}

.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: 19 additions & 9 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
@@ -330,20 +329,19 @@ def supports_listing(self) -> bool:
330329
...
331330

332331
@abstractmethod
333-
def list(self) -> AsyncGenerator[str, None]:
332+
def list(self) -> AsyncGenerator[str]:
334333
"""Retrieve all keys in the store.
335334
336335
Returns
337336
-------
338337
AsyncGenerator[str, None]
339338
"""
340-
...
341339

342340
@abstractmethod
343-
def list_prefix(self, prefix: str) -> AsyncGenerator[str, None]:
341+
def list_prefix(self, prefix: str) -> AsyncGenerator[str]:
344342
"""
345-
Retrieve all keys in the store that begin with a given prefix. Keys are returned with the
346-
common leading prefix removed.
343+
Retrieve all keys in the store that begin with a given prefix. Keys are returned relative
344+
to the root of the store.
347345
348346
Parameters
349347
----------
@@ -353,10 +351,9 @@ def list_prefix(self, prefix: str) -> AsyncGenerator[str, None]:
353351
-------
354352
AsyncGenerator[str, None]
355353
"""
356-
...
357354

358355
@abstractmethod
359-
def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
356+
def list_dir(self, prefix: str) -> AsyncGenerator[str]:
360357
"""
361358
Retrieve all keys and prefixes with a given prefix and which do not contain the character
362359
“/” after the given prefix.
@@ -369,7 +366,20 @@ def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
369366
-------
370367
AsyncGenerator[str, None]
371368
"""
372-
...
369+
370+
async def delete_dir(self, prefix: str) -> None:
371+
"""
372+
Remove all keys and prefixes in the store that begin with a given prefix.
373+
"""
374+
if not self.supports_deletes:
375+
raise NotImplementedError
376+
if not self.supports_listing:
377+
raise NotImplementedError
378+
self._check_writable()
379+
if not prefix.endswith("/"):
380+
prefix += "/"
381+
async for key in self.list_prefix(prefix):
382+
await self.delete(key)
373383

374384
def close(self) -> None:
375385
"""Close the store."""

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
@@ -393,6 +393,8 @@ async def save_array(
393393
_handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
394394
or _default_zarr_version()
395395
)
396+
if not isinstance(arr, NDArrayLike):
397+
raise TypeError("arr argument must be numpy or other NDArrayLike array")
396398

397399
mode = kwargs.pop("mode", None)
398400
store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options)
@@ -447,16 +449,26 @@ async def save_group(
447449
or _default_zarr_version()
448450
)
449451

452+
for arg in args:
453+
if not isinstance(arg, NDArrayLike):
454+
raise TypeError(
455+
"All arguments must be numpy or other NDArrayLike arrays (except store, path, storage_options, and zarr_format)"
456+
)
457+
for k, v in kwargs.items():
458+
if not isinstance(v, NDArrayLike):
459+
raise TypeError(f"Keyword argument '{k}' must be a numpy or other NDArrayLike array")
460+
450461
if len(args) == 0 and len(kwargs) == 0:
451462
raise ValueError("at least one array must be provided")
452463
aws = []
453464
for i, arr in enumerate(args):
465+
_path = f"{path}/arr_{i}" if path is not None else f"arr_{i}"
454466
aws.append(
455467
save_array(
456468
store,
457469
arr,
458470
zarr_format=zarr_format,
459-
path=f"{path}/arr_{i}",
471+
path=_path,
460472
storage_options=storage_options,
461473
)
462474
)
@@ -866,9 +878,8 @@ async def create(
866878
warnings.warn("meta_array is not yet implemented", RuntimeWarning, stacklevel=2)
867879

868880
mode = kwargs.pop("mode", None)
869-
if mode is None:
870-
if not isinstance(store, Store | StorePath):
871-
mode = "a"
881+
if mode is None and not isinstance(store, Store | StorePath):
882+
mode = "a"
872883

873884
store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options)
874885

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.

0 commit comments

Comments
 (0)