Skip to content

Commit dbb8532

Browse files
committed
[OPT] Respect the chunks and blocks of src, if any
1 parent 02e5f65 commit dbb8532

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/blosc2/proxy.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# LICENSE file in the root directory of this source tree)
77
#######################################################################
88
from abc import ABC, abstractmethod
9+
from collections.abc import Sequence
910

1011
import numpy as np
1112

@@ -600,6 +601,15 @@ def __init__(self, src, chunks: tuple | None = None, blocks: tuple | None = None
600601
self._shape = src.shape
601602
# Compute reasonable values for chunks and blocks
602603
cparams = blosc2.CParams(clevel=0)
604+
605+
def is_ints_sequence(src, attr):
606+
seq = getattr(src, attr, None)
607+
if not isinstance(seq, Sequence) or isinstance(seq, (str, bytes)):
608+
return False
609+
return all(isinstance(x, int) for x in seq)
610+
611+
chunks = src.chunks if chunks is None and is_ints_sequence(src, "chunks") else chunks
612+
blocks = src.blocks if blocks is None and is_ints_sequence(src, "blocks") else blocks
603613
self.chunks, self.blocks = blosc2.compute_chunks_blocks(
604614
self.shape, chunks, blocks, self.dtype, **{"cparams": cparams}
605615
)

0 commit comments

Comments
 (0)