Skip to content

Commit a971e9c

Browse files
committed
Merge branch 'main' of https://github.com/zarr-developers/zarr-python into feat/v2-v3-codecs
2 parents 51b9431 + c21d1f9 commit a971e9c

File tree

9 files changed

+69
-12
lines changed

9 files changed

+69
-12
lines changed

.github/workflows/releases.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
needs: [build_artifacts]
3737
runs-on: ubuntu-latest
3838
steps:
39-
- uses: actions/download-artifact@v4
39+
- uses: actions/download-artifact@v5
4040
with:
4141
name: releases
4242
path: dist
@@ -51,7 +51,7 @@ jobs:
5151
runs-on: ubuntu-latest
5252
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
5353
steps:
54-
- uses: actions/download-artifact@v4
54+
- uses: actions/download-artifact@v5
5555
with:
5656
name: releases
5757
path: dist

changes/3371.misc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure that tests for executable examples are run in a fresh python environment.

changes/3372.misc.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Make certain imports in ``zarr.abc.store`` local to method definitions. This minimizes the risk of
2+
circular imports when adding new classes to ``zarr.abc.store``.

codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ coverage:
33
patch:
44
default:
55
target: auto
6+
informational: true
67
project:
78
default:
89
target: auto

src/zarr/abc/codec.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ def _check_codecjson_v2(data: object) -> TypeGuard[CodecJSON_V2[str]]:
6060
return isinstance(data, Mapping) and "id" in data and isinstance(data["id"], str)
6161

6262

63-
CodecConfig_V3 = NamedConfig[str, Mapping[str, object]]
63+
CodecJSON_V3 = str | NamedConfig[str, Mapping[str, object]]
64+
"""The JSON representation of a codec for Zarr V3."""
6465

65-
CodecJSON_V3 = str | CodecConfig_V3
66-
67-
# The widest type we will accept for a codec JSON
66+
# The widest type we will *accept* for a codec JSON
6867
# This covers v2 and v3
6968
CodecJSON = str | Mapping[str, object]
69+
"""The widest type of JSON-like input that could specify a codec."""
7070

7171

7272
class BaseCodec(Metadata, Generic[CodecInput, CodecOutput]):

src/zarr/abc/numcodec.py

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,65 @@
66
class Numcodec(Protocol):
77
"""
88
A protocol that models the ``numcodecs.abc.Codec`` interface.
9+
10+
This protocol should be considered experimental. Expect the type annotations for ``buf`` and
11+
``out`` to narrow in the future.
912
"""
1013

1114
codec_id: str
1215

13-
def encode(self, buf: Any) -> Any: ...
16+
def encode(self, buf: Any) -> Any:
17+
"""Encode data from ``buf``.
18+
19+
Parameters
20+
----------
21+
buf : Any
22+
Data to be encoded.
23+
24+
Returns
25+
-------
26+
enc: Any
27+
Encoded data.
28+
"""
29+
...
1430

15-
def decode(self, buf: Any, out: Any | None = None) -> Any: ...
31+
def decode(self, buf: Any, out: Any | None = None) -> Any:
32+
"""
33+
Decode data in ``buf``.
1634
17-
def get_config(self) -> Any: ...
35+
Parameters
36+
----------
37+
buf : Any
38+
Encoded data.
39+
out : Any
40+
Writeable buffer to store decoded data. If provided, this buffer must
41+
be exactly the right size to store the decoded data.
42+
43+
Returns
44+
-------
45+
dec : Any
46+
Decoded data.
47+
"""
48+
...
49+
50+
def get_config(self) -> Any:
51+
"""
52+
Return a JSON-serializable configuration dictionary for this
53+
codec. Must include an ``'id'`` field with the codec identifier.
54+
"""
55+
...
1856

1957
@classmethod
20-
def from_config(cls, config: Any) -> Self: ...
58+
def from_config(cls, config: Any) -> Self:
59+
"""
60+
Instantiate a codec from a configuration dictionary.
61+
62+
Parameters
63+
----------
64+
config : Any
65+
A configuration dictionary for this codec.
66+
"""
67+
...
2168

2269

2370
def _is_numcodec_cls(obj: object) -> TypeGuard[type[Numcodec]]:

src/zarr/abc/store.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ async def getsize(self, key: str) -> int:
435435
# Note to implementers: this default implementation is very inefficient since
436436
# it requires reading the entire object. Many systems will have ways to get the
437437
# size of an object without reading it.
438+
# avoid circular import
438439
from zarr.core.buffer.core import default_buffer_prototype
439440

440441
value = await self.get(key, prototype=default_buffer_prototype())
@@ -475,6 +476,8 @@ async def getsize_prefix(self, prefix: str) -> int:
475476
# on to getting sizes. Ideally we would overlap those two, which should
476477
# improve tail latency and might reduce memory pressure (since not all keys
477478
# would be in memory at once).
479+
480+
# avoid circular import
478481
from zarr.core.common import concurrent_map
479482
from zarr.core.config import config
480483

src/zarr/core/_info.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from typing import TYPE_CHECKING, Literal
66

77
if TYPE_CHECKING:
8-
from zarr.abc.codec import ArrayArrayCodec, ArrayBytesCodec, BytesBytesCodec, Numcodec
8+
from zarr.abc.codec import ArrayArrayCodec, ArrayBytesCodec, BytesBytesCodec
9+
from zarr.abc.numcodec import Numcodec
910
from zarr.core.common import ZarrFormat
1011
from zarr.core.dtype.wrapper import TBaseDType, TBaseScalar, ZDType
1112

tests/test_examples.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ def test_scripts_can_run(script_path: Path, tmp_path: Path) -> None:
7272
# and then test its behavior.
7373
# This allows the example to be useful to users who don't have Zarr installed, but also testable.
7474
resave_script(script_path, dest_path)
75-
result = subprocess.run(["uv", "run", str(dest_path)], capture_output=True, text=True)
75+
result = subprocess.run(
76+
["uv", "run", "--refresh", str(dest_path)], capture_output=True, text=True
77+
)
7678
assert result.returncode == 0, (
7779
f"Script at {script_path} failed to run. Output: {result.stdout} Error: {result.stderr}"
7880
)

0 commit comments

Comments
 (0)