From eeebe2401c375887389c0fdc6474e6e5c34de04f Mon Sep 17 00:00:00 2001 From: brokkoli71 Date: Wed, 25 Sep 2024 18:10:32 +0200 Subject: [PATCH 1/3] set default typesize=0 --- tests/test_v3.py | 6 +++--- zarrita/codecs.py | 2 +- zarrita/metadata.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_v3.py b/tests/test_v3.py index 5579830..e8e8430 100644 --- a/tests/test_v3.py +++ b/tests/test_v3.py @@ -63,7 +63,7 @@ def test_sharding( [ codecs.transpose_codec("F"), codecs.bytes_codec(), - codecs.blosc_codec(typesize=data.dtype.itemsize, cname="lz4"), + codecs.blosc_codec(cname="lz4"), ], index_location=index_location, ) @@ -516,7 +516,7 @@ def test_open_sharding(store: Store): [ codecs.transpose_codec("F"), codecs.bytes_codec(), - codecs.blosc_codec(typesize=4), + codecs.blosc_codec(), ], ) ], @@ -675,7 +675,7 @@ def test_write_partial_sharded_chunks(store: Store): chunk_shape=(10, 10), codecs=[ codecs.bytes_codec(), - codecs.blosc_codec(typesize=data.dtype.itemsize), + codecs.blosc_codec(), ], ) ], diff --git a/zarrita/codecs.py b/zarrita/codecs.py index 29d2f54..fb8f271 100644 --- a/zarrita/codecs.py +++ b/zarrita/codecs.py @@ -545,7 +545,7 @@ def compute_encoded_size(self, input_byte_length: int) -> int: def blosc_codec( - typesize: int, + typesize: int = 0, cname: Literal["lz4", "lz4hc", "blosclz", "zstd", "snappy", "zlib"] = "zstd", clevel: int = 5, shuffle: Literal["noshuffle", "shuffle", "bitshuffle"] = "noshuffle", diff --git a/zarrita/metadata.py b/zarrita/metadata.py index 34eacdd..60a270b 100644 --- a/zarrita/metadata.py +++ b/zarrita/metadata.py @@ -149,7 +149,7 @@ def encode_chunk_key(self, chunk_coords: ChunkCoords) -> str: @frozen class BloscCodecConfigurationMetadata: - typesize: int + typesize: int = 0 cname: Literal["lz4", "lz4hc", "blosclz", "zstd", "snappy", "zlib"] = "zstd" clevel: int = 5 shuffle: BloscShuffle = "noshuffle" From 884150ee053b600340f6c0def2034bc543860d43 Mon Sep 17 00:00:00 2001 From: brokkoli71 Date: Sat, 28 Sep 2024 14:18:09 +0200 Subject: [PATCH 2/3] set default typesize=None --- zarrita/codecs.py | 8 +++++--- zarrita/metadata.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/zarrita/codecs.py b/zarrita/codecs.py index fb8f271..17e24b0 100644 --- a/zarrita/codecs.py +++ b/zarrita/codecs.py @@ -268,12 +268,14 @@ def from_metadata( cls, codec_metadata: BloscCodecMetadata, array_metadata: CoreArrayMetadata ) -> BloscCodec: configuration = codec_metadata.configuration - if configuration.typesize == 0: + if configuration.typesize is None: configuration = evolve( configuration, typesize=array_metadata.data_type.byte_count ) + + # Prepare config_dict for the numcodecs.blosc.Blosc constructor config_dict = asdict(codec_metadata.configuration) - config_dict.pop("typesize", None) + config_dict.pop("typesize") map_shuffle_str_to_int = {"noshuffle": 0, "shuffle": 1, "bitshuffle": 2} config_dict["shuffle"] = map_shuffle_str_to_int[config_dict["shuffle"]] return cls( @@ -545,7 +547,7 @@ def compute_encoded_size(self, input_byte_length: int) -> int: def blosc_codec( - typesize: int = 0, + typesize: int | None = None, cname: Literal["lz4", "lz4hc", "blosclz", "zstd", "snappy", "zlib"] = "zstd", clevel: int = 5, shuffle: Literal["noshuffle", "shuffle", "bitshuffle"] = "noshuffle", diff --git a/zarrita/metadata.py b/zarrita/metadata.py index 60a270b..7125c82 100644 --- a/zarrita/metadata.py +++ b/zarrita/metadata.py @@ -149,7 +149,7 @@ def encode_chunk_key(self, chunk_coords: ChunkCoords) -> str: @frozen class BloscCodecConfigurationMetadata: - typesize: int = 0 + typesize: int | None = None cname: Literal["lz4", "lz4hc", "blosclz", "zstd", "snappy", "zlib"] = "zstd" clevel: int = 5 shuffle: BloscShuffle = "noshuffle" From 3523ab7c03513bb510c4b8dcd52ed9caf10fedec Mon Sep 17 00:00:00 2001 From: brokkoli71 Date: Sat, 28 Sep 2024 14:41:40 +0200 Subject: [PATCH 3/3] fix typing with Optional[] --- zarrita/codecs.py | 2 +- zarrita/metadata.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/zarrita/codecs.py b/zarrita/codecs.py index 17e24b0..e4721f8 100644 --- a/zarrita/codecs.py +++ b/zarrita/codecs.py @@ -547,7 +547,7 @@ def compute_encoded_size(self, input_byte_length: int) -> int: def blosc_codec( - typesize: int | None = None, + typesize: Optional[int] = None, cname: Literal["lz4", "lz4hc", "blosclz", "zstd", "snappy", "zlib"] = "zstd", clevel: int = 5, shuffle: Literal["noshuffle", "shuffle", "bitshuffle"] = "noshuffle", diff --git a/zarrita/metadata.py b/zarrita/metadata.py index 7125c82..baf77e9 100644 --- a/zarrita/metadata.py +++ b/zarrita/metadata.py @@ -149,7 +149,7 @@ def encode_chunk_key(self, chunk_coords: ChunkCoords) -> str: @frozen class BloscCodecConfigurationMetadata: - typesize: int | None = None + typesize: Optional[int] = None cname: Literal["lz4", "lz4hc", "blosclz", "zstd", "snappy", "zlib"] = "zstd" clevel: int = 5 shuffle: BloscShuffle = "noshuffle"