Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions python/zarrista/_array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ from typing import TypeAlias, Unpack

from zarr_metadata import ArrayMetadataV3, JSONValue

from zarrista.codec import CodecOptions
from zarrista.codec import (
ArrayToArrayCodec,
ArrayToBytesCodec,
BytesToBytesCodec,
CodecOptions,
)

from ._chunks import ChunkGrid
from ._codec import CodecChain
from ._decoded_array import DecodedArray
from ._dtype import DataType
from ._store import AsyncStore, FilesystemStore, MemoryStore
Expand Down Expand Up @@ -34,8 +38,14 @@ class Array:
def chunk_grid(self) -> ChunkGrid:
"""The chunk grid of the array."""
@property
def codecs(self) -> CodecChain:
"""The codec chain used to encode and decode the array's chunks."""
def compressors(self) -> list[BytesToBytesCodec]:
"""The bytes-to-bytes codecs ("compressors")."""
@property
def filters(self) -> list[ArrayToArrayCodec]:
"""The array-to-array codecs ("filters")."""
@property
def serializer(self) -> ArrayToBytesCodec:
"""The array-to-bytes codec ("serializer")."""
@property
def dimension_names(self) -> list[str | None] | None:
"""The dimension names, if any were specified."""
Expand Down Expand Up @@ -97,8 +107,14 @@ class AsyncArray:
def chunk_grid(self) -> ChunkGrid:
"""The chunk grid of the array."""
@property
def codecs(self) -> CodecChain:
"""The codec chain used to encode and decode the array's chunks."""
def compressors(self) -> list[BytesToBytesCodec]:
"""The bytes-to-bytes codecs ("compressors")."""
@property
def filters(self) -> list[ArrayToArrayCodec]:
"""The array-to-array codecs ("filters")."""
@property
def serializer(self) -> ArrayToBytesCodec:
"""The array-to-bytes codec ("serializer")."""
@property
def dimension_names(self) -> list[str | None] | None:
"""The dimension names, if any were specified."""
Expand Down
20 changes: 10 additions & 10 deletions python/zarrista/codec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

from zarrista._zarrista.codec import (
ArrayToArrayCodec,
Blosc,
ArrayToBytesCodec,
BytesToBytesCodec,
CodecChain,
Crc32c,
Gzip,
Zstd,
bitround,
blosc,
crc32c,
gzip,
transpose,
zstd,
)

__all__ = [
"ArrayToArrayCodec",
"Blosc",
"ArrayToBytesCodec",
"BytesToBytesCodec",
"CodecChain",
"Crc32c",
"Gzip",
"Zstd",
"bitround",
"blosc",
"crc32c",
"gzip",
"transpose",
"zstd",
]
10 changes: 5 additions & 5 deletions python/zarrista/codec/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from zarrista.codec._array_to_array import ArrayToArrayCodec as ArrayToArrayCodec
from zarrista.codec._array_to_array import bitround as bitround
from zarrista.codec._array_to_array import transpose as transpose
from zarrista.codec._array_to_bytes import ArrayToBytesCodec as ArrayToBytesCodec
from zarrista.codec._bytes_to_bytes import BytesToBytesCodec as BytesToBytesCodec
from zarrista.codec._bytes_to_bytes._blosc import Blosc as Blosc
from zarrista.codec._bytes_to_bytes._crc32c import Crc32c as Crc32c
from zarrista.codec._bytes_to_bytes._gzip import Gzip as Gzip
from zarrista.codec._bytes_to_bytes._zstd import Zstd as Zstd
from zarrista.codec._codec_chain import CodecChain as CodecChain
from zarrista.codec._bytes_to_bytes._blosc import blosc as blosc
from zarrista.codec._bytes_to_bytes._crc32c import crc32c as crc32c
from zarrista.codec._bytes_to_bytes._gzip import gzip as gzip
from zarrista.codec._bytes_to_bytes._zstd import zstd as zstd
from zarrista.codec._options import CodecOptions as CodecOptions
14 changes: 14 additions & 0 deletions python/zarrista/codec/_array_to_array.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
from zarr_metadata import JSONValue

from zarrista._array_bytes import ArrayBytes
from zarrista._dtype import DataType
from zarrista._fill_value import FillValue

class ArrayToArrayCodec:
"""A Zarr v3 array-to-array codec."""

@property
def name(self) -> str | None:
"""The codec's Zarr v3 name (e.g. `"transpose"`), if any."""
@property
def config(self) -> JSONValue | None:
"""The codec's Zarr v3 configuration as a dict, if any."""
@staticmethod
def from_config(metadata: JSONValue) -> ArrayToArrayCodec:
"""Build a codec from its Zarr v3 metadata.

For example `{"name": "transpose", "configuration": {"order": [1, 0]}}`.
"""
def encoded_data_type(self, decoded_data_type: DataType) -> DataType:
"""Return the data type produced by encoding `decoded_data_type`."""
def encoded_fill_value(
Expand Down
17 changes: 17 additions & 0 deletions python/zarrista/codec/_array_to_bytes.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from zarr_metadata import JSONValue

class ArrayToBytesCodec:
"""A Zarr v3 array-to-bytes codec (the "serializer")."""

@property
def name(self) -> str | None:
"""The codec's Zarr v3 name (e.g. `"bytes"`, `"sharding_indexed"`), if any."""
@property
def config(self) -> JSONValue | None:
"""The codec's Zarr v3 configuration as a dict, if any."""
@staticmethod
def from_config(metadata: JSONValue) -> ArrayToBytesCodec:
"""Build a codec from its Zarr v3 metadata.

For example `{"name": "bytes", "configuration": {"endian": "little"}}`.
"""
14 changes: 14 additions & 0 deletions python/zarrista/codec/_bytes_to_bytes/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
from zarr_metadata import JSONValue

class BytesToBytesCodec:
"""A Zarr v3 bytes-to-bytes codec."""

@property
def name(self) -> str | None:
"""The codec's Zarr v3 name (e.g. `"blosc"`), if any."""
@property
def config(self) -> JSONValue | None:
"""The codec's Zarr v3 configuration as a dict, if any."""
@staticmethod
def from_config(metadata: JSONValue) -> BytesToBytesCodec:
"""Build a codec from its Zarr v3 metadata.

For example `{"name": "gzip", "configuration": {"level": 5}}`.
"""
def encode(self, decoded_value: bytes) -> bytes:
"""Encode chunk bytes for this codec."""
43 changes: 15 additions & 28 deletions python/zarrista/codec/_bytes_to_bytes/_blosc.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Literal, TypeAlias

from zarr_metadata.v3.codec.blosc import BloscCodecConfiguration

from zarrista.codec._bytes_to_bytes import BytesToBytesCodec

BloscCompressor: TypeAlias = Literal[
Expand All @@ -17,29 +15,18 @@ BloscCompressor: TypeAlias = Literal[
BloscShuffle: TypeAlias = Literal["noshuffle", "shuffle", "bitshuffle"]
"""A `blosc` shuffle mode."""

class Blosc(BytesToBytesCodec):
"""The `blosc` bytes-to-bytes codec."""

def __init__(
self,
cname: BloscCompressor,
clevel: int,
shuffle_mode: BloscShuffle,
*,
blocksize: int | None = None,
typesize: int | None = None,
) -> None:
"""Construct a `blosc` codec from its parameters.

`clevel` is the compression level, an integer from 0 (no compression)
to 9 (most compression). `typesize` is required (a positive integer)
whenever `shuffle_mode` is not `"noshuffle"`. The block size is chosen
automatically when `blocksize` is `None` or `0`.
"""
@staticmethod
def from_config(config: BloscCodecConfiguration) -> Blosc:
"""Construct a `blosc` codec from a configuration mapping.

For example `{"cname": "lz4", "clevel": 5, "shuffle": "shuffle",
"typesize": 4, "blocksize": 0}`.
"""
def blosc(
cname: BloscCompressor,
clevel: int,
shuffle_mode: BloscShuffle,
*,
blocksize: int | None = None,
typesize: int | None = None,
) -> BytesToBytesCodec:
"""Construct a `blosc` codec from its parameters.

`clevel` is the compression level, an integer from 0 (no compression) to 9
(most compression). `typesize` is required (a positive integer) whenever
`shuffle_mode` is not `"noshuffle"`. The block size is chosen automatically
when `blocksize` is `None` or `0`.
"""
21 changes: 4 additions & 17 deletions python/zarrista/codec/_bytes_to_bytes/_crc32c.pyi
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
from typing import TypedDict

from zarrista.codec._bytes_to_bytes import BytesToBytesCodec

class Crc32cConfig(TypedDict): ...

class Crc32c(BytesToBytesCodec):
"""The `crc32c` bytes-to-bytes codec."""

def __init__(self) -> None:
"""Construct a `crc32c` codec.

Appends a CRC32C checksum to the encoded bytestream.
"""
@staticmethod
def from_config(config: Crc32cConfig) -> Crc32c:
"""Construct a `crc32c` codec from a configuration mapping, e.g. `{}`.
def crc32c() -> BytesToBytesCodec:
"""Construct a `crc32c` codec.

The `crc32c` codec takes no configuration, so the mapping is empty.
"""
Appends a CRC32C checksum to the encoded bytestream.
"""
18 changes: 5 additions & 13 deletions python/zarrista/codec/_bytes_to_bytes/_gzip.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
from zarr_metadata.v3.codec.gzip import GzipCodecConfiguration

from zarrista.codec._bytes_to_bytes import BytesToBytesCodec

class Gzip(BytesToBytesCodec):
"""The `gzip` bytes-to-bytes codec."""

def __init__(self, level: int) -> None:
"""Construct a `gzip` codec.
def gzip(level: int) -> BytesToBytesCodec:
"""Construct a `gzip` codec.

`level` is the compression level, an integer from 0 (no compression)
to 9 (most compression).
"""
@staticmethod
def from_config(config: GzipCodecConfiguration) -> Gzip:
"""Construct a `gzip` codec from a config mapping, e.g. `{"level": 5}`."""
`level` is the compression level, an integer from 0 (no compression) to 9
(most compression).
"""
21 changes: 5 additions & 16 deletions python/zarrista/codec/_bytes_to_bytes/_zstd.pyi
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
from zarr_metadata.v3.codec.zstd import ZstdCodecConfiguration

from zarrista.codec._bytes_to_bytes import BytesToBytesCodec

class Zstd(BytesToBytesCodec):
"""The `zstd` bytes-to-bytes codec."""

def __init__(self, level: int, checksum: bool) -> None:
"""Construct a `zstd` codec.

`level` is the compression level. When `checksum` is true, a checksum
is written to (and verified on decode from) the encoded bytestream.
"""
@staticmethod
def from_config(config: ZstdCodecConfiguration) -> Zstd:
"""Construct a `zstd` codec from a configuration mapping.
def zstd(level: int, checksum: bool) -> BytesToBytesCodec:
"""Construct a `zstd` codec.

For example, `{"level": 5, "checksum": false}`.
"""
`level` is the compression level. When `checksum` is true, a checksum is
written to (and verified on decode from) the encoded bytestream.
"""
9 changes: 0 additions & 9 deletions python/zarrista/codec/_codec_chain.pyi

This file was deleted.

28 changes: 26 additions & 2 deletions src/array/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ macro_rules! array_metadata_accessors {
self.inner.chunk_grid().clone().into()
}

/// The bytes-to-bytes codecs ("compressors").
#[getter]
fn codecs(&self) -> $crate::codec::PyCodecChain {
self.inner.codecs().into()
fn compressors(&self) -> Vec<$crate::codec::PyBytesToBytesCodec> {
let codecs = self.inner.codecs();
codecs
.bytes_to_bytes_codecs()
.iter()
.map(|c| $crate::codec::PyBytesToBytesCodec::new(c.clone()))
.collect()
}

/// The dimension names, if any were specified.
Expand All @@ -38,6 +44,17 @@ macro_rules! array_metadata_accessors {
self.inner.data_type().clone().into()
}

/// The array-to-array codecs ("filters").
#[getter]
fn filters(&self) -> Vec<$crate::codec::PyArrayToArrayCodec> {
let codecs = self.inner.codecs();
codecs
.array_to_array_codecs()
.iter()
.map(|f| $crate::codec::PyArrayToArrayCodec::new(f.clone()))
.collect()
}

#[getter]
fn metadata(&self) -> $crate::metadata::PyArrayMetadata {
self.inner.metadata().clone().into()
Expand All @@ -55,6 +72,13 @@ macro_rules! array_metadata_accessors {
self.inner.path().as_str()
}

/// The array-to-bytes codec ("serializer").
#[getter]
fn serializer(&self) -> $crate::codec::PyArrayToBytesCodec {
let codecs = self.inner.codecs();
$crate::codec::PyArrayToBytesCodec::new(codecs.array_to_bytes_codec().clone())
}

/// The array shape.
#[getter]
fn shape(&self) -> &[u64] {
Expand Down
Loading
Loading