Skip to content

Commit

Permalink
Merge branch 'main' into refactor/store-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamman authored Nov 8, 2024
2 parents ee47265 + 498cb78 commit b5e5216
Show file tree
Hide file tree
Showing 36 changed files with 258 additions and 220 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
with:
name: releases
path: dist
- uses: pypa/gh-action-pypi-publish@v1.10.3
- uses: pypa/gh-action-pypi-publish@v1.11.0
with:
user: __token__
password: ${{ secrets.pypi_password }}
Expand Down
17 changes: 8 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ jobs:
numpy-version: '2.1'
dependency-set: 'optional'
os: 'macos-latest'
# https://github.com/zarr-developers/zarr-python/issues/2438
# - python-version: '3.11'
# numpy-version: '1.25'
# dependency-set: 'optional'
# os: 'windows-latest'
# - python-version: '3.13'
# numpy-version: '2.1'
# dependency-set: 'optional'
# os: 'windows-latest'
- python-version: '3.11'
numpy-version: '1.25'
dependency-set: 'optional'
os: 'windows-latest'
- python-version: '3.13'
numpy-version: '2.1'
dependency-set: 'optional'
os: 'windows-latest'
runs-on: ${{ matrix.os }}

steps:
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.0
rev: v0.7.2
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand All @@ -22,7 +22,7 @@ repos:
hooks:
- id: check-yaml
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.12.1
rev: v1.13.0
hooks:
- id: mypy
files: src|tests
Expand Down
13 changes: 10 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ gpu = [
docs = [
'sphinx==8.1.3',
'sphinx-autobuild>=2021.3.14',
'sphinx-autoapi==3.3.2',
'sphinx-autoapi==3.3.3',
'sphinx_design',
'sphinx-issues',
'sphinx-copybutton',
Expand Down Expand Up @@ -269,19 +269,25 @@ extend-exclude = [
extend-select = [
"ANN", # flake8-annotations
"B", # flake8-bugbear
"EXE", # flake8-executable
"C4", # flake8-comprehensions
"FA", # flake8-future-annotations
"FLY", # flynt
"FURB", # refurb
"G", # flake8-logging-format
"I", # isort
"ISC", # flake8-implicit-str-concat
"LOG", # flake8-logging
"PERF", # Perflint
"PIE", # flake8-pie
"PGH", # pygrep-hooks
"PT", # flake8-pytest-style
"PYI", # flake8-pyi
"RSE", # flake8-raise
"RET", # flake8-return
"RSE", # flake8-raise
"RUF",
"SIM", # flake8-simplify
"SLOT", # flake8-slots
"TCH", # flake8-type-checking
"TRY", # tryceratops
"UP", # pyupgrade
Expand All @@ -298,6 +304,7 @@ ignore = [
"RET505",
"RET506",
"RUF005",
"SIM108",
"TRY003",
"UP027", # deprecated
"UP038", # https://github.com/astral-sh/ruff/issues/7871
Expand All @@ -319,7 +326,7 @@ ignore = [
]

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

[tool.mypy]
python_version = "3.11"
Expand Down
1 change: 0 additions & 1 deletion src/zarr/abc/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def validate(self, *, shape: ChunkCoords, dtype: np.dtype[Any], chunk_grid: Chun
chunk_grid : ChunkGrid
The array chunk grid
"""
...

async def _decode_single(self, chunk_data: CodecOutput, chunk_spec: ArraySpec) -> CodecInput:
raise NotImplementedError
Expand Down
1 change: 0 additions & 1 deletion src/zarr/abc/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ def from_dict(cls, data: dict[str, JSON]) -> Self:
"""
Create an instance of the model from a dictionary
"""
...

return cls(**data)
28 changes: 19 additions & 9 deletions src/zarr/abc/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ async def _set_many(self, values: Iterable[tuple[str, Buffer]]) -> None:
Insert multiple (key, value) pairs into storage.
"""
await gather(*starmap(self.set, values))
return

@property
@abstractmethod
Expand Down Expand Up @@ -296,20 +295,19 @@ def supports_listing(self) -> bool:
...

@abstractmethod
def list(self) -> AsyncGenerator[str, None]:
def list(self) -> AsyncGenerator[str]:
"""Retrieve all keys in the store.
Returns
-------
AsyncGenerator[str, None]
"""
...

@abstractmethod
def list_prefix(self, prefix: str) -> AsyncGenerator[str, None]:
def list_prefix(self, prefix: str) -> AsyncGenerator[str]:
"""
Retrieve all keys in the store that begin with a given prefix. Keys are returned as
absolute paths (i.e. including the prefix).
Retrieve all keys in the store that begin with a given prefix. Keys are returned relative
to the root of the store.
Parameters
----------
Expand All @@ -319,10 +317,9 @@ def list_prefix(self, prefix: str) -> AsyncGenerator[str, None]:
-------
AsyncGenerator[str, None]
"""
...

@abstractmethod
def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
def list_dir(self, prefix: str) -> AsyncGenerator[str]:
"""
Retrieve all keys and prefixes with a given prefix and which do not contain the character
“/” after the given prefix.
Expand All @@ -335,7 +332,20 @@ def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
-------
AsyncGenerator[str, None]
"""
...

async def delete_dir(self, prefix: str) -> None:
"""
Remove all keys and prefixes in the store that begin with a given prefix.
"""
if not self.supports_deletes:
raise NotImplementedError
if not self.supports_listing:
raise NotImplementedError
self._check_writable()
if not prefix.endswith("/"):
prefix += "/"
async for key in self.list_prefix(prefix):
await self.delete(key)

async def delete_dir(self, prefix: str) -> None:
"""
Expand Down
17 changes: 15 additions & 2 deletions src/zarr/api/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import numpy.typing as npt

from zarr.core.array import Array, AsyncArray, get_array_metadata
from zarr.core.buffer import NDArrayLike
from zarr.core.common import (
JSON,
AccessModeLiteral,
Expand Down Expand Up @@ -422,6 +423,8 @@ async def save_array(
_handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
or _default_zarr_version()
)
if not isinstance(arr, NDArrayLike):
raise TypeError("arr argument must be numpy or other NDArrayLike array")

mode = kwargs.pop("mode", "a")
store_mode = _handle_store_mode(mode)
Expand Down Expand Up @@ -484,16 +487,27 @@ async def save_group(
or _default_zarr_version()
)

for arg in args:
if not isinstance(arg, NDArrayLike):
raise TypeError(
"All arguments must be numpy or other NDArrayLike arrays (except store, path, storage_options, and zarr_format)"
)
for k, v in kwargs.items():
if not isinstance(v, NDArrayLike):
raise TypeError(f"Keyword argument '{k}' must be a numpy or other NDArrayLike array")

if len(args) == 0 and len(kwargs) == 0:
raise ValueError("at least one array must be provided")
aws = []
for i, arr in enumerate(args):
_path = f"{path}/arr_{i}" if path is not None else f"arr_{i}"
aws.append(
save_array(
store_path,
arr,
zarr_format=zarr_format,
path=f"arr_{i}",
path=_path,
storage_options=storage_options,
)
)
for k, arr in kwargs.items():
Expand Down Expand Up @@ -923,7 +937,6 @@ async def create(
store, path=path, mode=store_mode, storage_options=storage_options
)
await store_path._init(mode)

return await AsyncArray.create(
store_path,
shape=shape,
Expand Down
2 changes: 0 additions & 2 deletions src/zarr/codecs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
from zarr.codecs.bytes import BytesCodec, Endian
from zarr.codecs.crc32c_ import Crc32cCodec
from zarr.codecs.gzip import GzipCodec
from zarr.codecs.pipeline import BatchedCodecPipeline
from zarr.codecs.sharding import ShardingCodec, ShardingCodecIndexLocation
from zarr.codecs.transpose import TransposeCodec
from zarr.codecs.vlen_utf8 import VLenBytesCodec, VLenUTF8Codec
from zarr.codecs.zstd import ZstdCodec
from zarr.core.metadata.v3 import DataType

__all__ = [
"BatchedCodecPipeline",
"BloscCname",
"BloscCodec",
"BloscShuffle",
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/codecs/gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
def parse_gzip_level(data: JSON) -> int:
if not isinstance(data, (int)):
raise TypeError(f"Expected int, got {type(data)}")
if data not in range(0, 10):
if data not in range(10):
raise ValueError(
f"Expected an integer from the inclusive range (0, 9). Got {data} instead."
)
Expand Down
Empty file removed src/zarr/codecs/registry.py
Empty file.
2 changes: 1 addition & 1 deletion src/zarr/codecs/sharding.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def create_empty(
def __setitem__(self, chunk_coords: ChunkCoords, value: Buffer) -> None:
chunk_start = len(self.buf)
chunk_length = len(value)
self.buf = self.buf + value
self.buf += value
self.index.set_chunk_slice(chunk_coords, slice(chunk_start, chunk_start + chunk_length))

def __delitem__(self, chunk_coords: ChunkCoords) -> None:
Expand Down
4 changes: 4 additions & 0 deletions src/zarr/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from __future__ import annotations

from zarr.core.buffer import Buffer, NDBuffer # noqa: F401
from zarr.core.codec_pipeline import BatchedCodecPipeline # noqa: F401
Loading

0 comments on commit b5e5216

Please sign in to comment.