Skip to content

Commit 83c26e9

Browse files
authored
Merge branch 'main' into tom/feature/tree
2 parents 78828ab + 498cb78 commit 83c26e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+862
-375
lines changed

.github/workflows/gpu_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
strategy:
2626
matrix:
2727
python-version: ['3.11']
28-
numpy-version: ['2.0']
28+
numpy-version: ['2.1']
2929
dependency-set: ["minimal"]
3030

3131
steps:

.github/workflows/hypothesis.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
strategy:
2727
matrix:
2828
python-version: ['3.11']
29-
numpy-version: ['1.26']
29+
numpy-version: ['2.1']
3030
dependency-set: ["optional"]
3131

3232
steps:

.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 }}

.github/workflows/test.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,32 @@ concurrency:
1616

1717
jobs:
1818
test:
19-
name: py=${{ matrix.python-version }}, np=${{ matrix.numpy-version }}, deps=${{ matrix.dependency-set }}
19+
name: os=${{ matrix.os }}, py=${{ matrix.python-version }}, np=${{ matrix.numpy-version }}, deps=${{ matrix.dependency-set }}
2020

21-
runs-on: ubuntu-latest
2221
strategy:
2322
matrix:
2423
python-version: ['3.11', '3.12', '3.13']
25-
numpy-version: ['1.25', '1.26', '2.0']
24+
numpy-version: ['1.25', '2.1']
2625
dependency-set: ["minimal", "optional"]
26+
os: ["ubuntu-latest"]
27+
include:
28+
- python-version: '3.11'
29+
numpy-version: '1.25'
30+
dependency-set: 'optional'
31+
os: 'macos-latest'
32+
- python-version: '3.13'
33+
numpy-version: '2.1'
34+
dependency-set: 'optional'
35+
os: 'macos-latest'
36+
- python-version: '3.11'
37+
numpy-version: '1.25'
38+
dependency-set: 'optional'
39+
os: 'windows-latest'
40+
- python-version: '3.13'
41+
numpy-version: '2.1'
42+
dependency-set: 'optional'
43+
os: 'windows-latest'
44+
runs-on: ${{ matrix.os }}
2745

2846
steps:
2947
- uses: actions/checkout@v4

.pre-commit-config.yaml

Lines changed: 2 additions & 4 deletions
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.0
10+
rev: v0.7.2
1111
hooks:
1212
- id: ruff
1313
args: ["--fix", "--show-fixes"]
@@ -22,7 +22,7 @@ repos:
2222
hooks:
2323
- id: check-yaml
2424
- repo: https://github.com/pre-commit/mirrors-mypy
25-
rev: v1.12.1
25+
rev: v1.13.0
2626
hooks:
2727
- id: mypy
2828
files: src|tests
@@ -37,8 +37,6 @@ repos:
3737
- universal-pathlib
3838
# Tests
3939
- pytest
40-
# Zarr v2
41-
- types-redis
4240
- repo: https://github.com/scientific-python/cookie
4341
rev: 2024.08.19
4442
hooks:

pyproject.toml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ test = [
6161
"pytest",
6262
"pytest-cov",
6363
"msgpack",
64-
"lmdb",
6564
"s3fs",
6665
"pytest-asyncio",
6766
"moto[s3]",
@@ -84,21 +83,19 @@ gpu = [
8483
docs = [
8584
'sphinx==8.1.3',
8685
'sphinx-autobuild>=2021.3.14',
87-
'sphinx-autoapi==3.3.2',
86+
'sphinx-autoapi==3.3.3',
8887
'sphinx_design',
8988
'sphinx-issues',
9089
'sphinx-copybutton',
9190
'pydata-sphinx-theme',
9291
'numpydoc',
9392
'numcodecs[msgpack]',
9493
'msgpack',
95-
'lmdb',
9694
]
9795
extra = [
9896
'msgpack',
9997
]
10098
optional = [
101-
'lmdb',
10299
'universal-pathlib>=0.0.22',
103100
'rich'
104101
]
@@ -139,17 +136,17 @@ features = ["test", "extra"]
139136

140137
[[tool.hatch.envs.test.matrix]]
141138
python = ["3.11", "3.12", "3.13"]
142-
numpy = ["1.25", "1.26", "2.0"]
139+
numpy = ["1.25", "2.1"]
143140
version = ["minimal"]
144141

145142
[[tool.hatch.envs.test.matrix]]
146143
python = ["3.11", "3.12", "3.13"]
147-
numpy = ["1.25", "1.26", "2.0"]
144+
numpy = ["1.25", "2.1"]
148145
features = ["optional"]
149146

150147
[[tool.hatch.envs.test.matrix]]
151148
python = ["3.11", "3.12", "3.13"]
152-
numpy = ["1.25", "1.26", "2.0"]
149+
numpy = ["1.25", "2.1"]
153150
features = ["gpu"]
154151

155152
[tool.hatch.envs.test.scripts]
@@ -170,7 +167,7 @@ features = ["test", "extra", "gpu"]
170167

171168
[[tool.hatch.envs.gputest.matrix]]
172169
python = ["3.11", "3.12", "3.13"]
173-
numpy = ["1.25", "1.26", "2.0"]
170+
numpy = ["1.25", "2.1"]
174171
version = ["minimal"]
175172

176173
[tool.hatch.envs.gputest.scripts]
@@ -276,19 +273,25 @@ extend-exclude = [
276273
extend-select = [
277274
"ANN", # flake8-annotations
278275
"B", # flake8-bugbear
276+
"EXE", # flake8-executable
279277
"C4", # flake8-comprehensions
278+
"FA", # flake8-future-annotations
280279
"FLY", # flynt
281280
"FURB", # refurb
282281
"G", # flake8-logging-format
283282
"I", # isort
284283
"ISC", # flake8-implicit-str-concat
284+
"LOG", # flake8-logging
285285
"PERF", # Perflint
286+
"PIE", # flake8-pie
286287
"PGH", # pygrep-hooks
287288
"PT", # flake8-pytest-style
288289
"PYI", # flake8-pyi
289-
"RSE", # flake8-raise
290290
"RET", # flake8-return
291+
"RSE", # flake8-raise
291292
"RUF",
293+
"SIM", # flake8-simplify
294+
"SLOT", # flake8-slots
292295
"TCH", # flake8-type-checking
293296
"TRY", # tryceratops
294297
"UP", # pyupgrade
@@ -305,6 +308,7 @@ ignore = [
305308
"RET505",
306309
"RET506",
307310
"RUF005",
311+
"SIM108",
308312
"TRY003",
309313
"UP027", # deprecated
310314
"UP038", # https://github.com/astral-sh/ruff/issues/7871
@@ -326,7 +330,7 @@ ignore = [
326330
]
327331

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

331335
[tool.mypy]
332336
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: 22 additions & 7 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,15 +393,21 @@ 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)
401+
if np.isscalar(arr):
402+
arr = np.array(arr)
403+
shape = arr.shape
404+
chunks = getattr(arr, "chunks", None) # for array-likes with chunks attribute
399405
new = await AsyncArray.create(
400406
store_path,
401407
zarr_format=zarr_format,
402-
shape=arr.shape,
408+
shape=shape,
403409
dtype=arr.dtype,
404-
chunks=arr.shape,
410+
chunks=chunks,
405411
**kwargs,
406412
)
407413
await new.setitem(slice(None), arr)
@@ -443,16 +449,26 @@ async def save_group(
443449
or _default_zarr_version()
444450
)
445451

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+
446461
if len(args) == 0 and len(kwargs) == 0:
447462
raise ValueError("at least one array must be provided")
448463
aws = []
449464
for i, arr in enumerate(args):
465+
_path = f"{path}/arr_{i}" if path is not None else f"arr_{i}"
450466
aws.append(
451467
save_array(
452468
store,
453469
arr,
454470
zarr_format=zarr_format,
455-
path=f"{path}/arr_{i}",
471+
path=_path,
456472
storage_options=storage_options,
457473
)
458474
)
@@ -862,9 +878,8 @@ async def create(
862878
warnings.warn("meta_array is not yet implemented", RuntimeWarning, stacklevel=2)
863879

864880
mode = kwargs.pop("mode", None)
865-
if mode is None:
866-
if not isinstance(store, Store | StorePath):
867-
mode = "a"
881+
if mode is None and not isinstance(store, Store | StorePath):
882+
mode = "a"
868883

869884
store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options)
870885

0 commit comments

Comments
 (0)