Skip to content

Commit d19a4db

Browse files
committed
Honor nested cparams properties in kwargs
1 parent 261ca6e commit d19a4db

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

blosc2/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class SplitMode(Enum):
3333
"""
3434
Available split modes.
3535
"""
36-
3736
ALWAYS_SPLIT = 1
3837
NEVER_SPLIT = 2
3938
AUTO_SPLIT = 3

blosc2/core.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -597,13 +597,13 @@ def pack_tensor(tensor, chunksize=None, **kwargs):
597597
import numpy as np
598598
arr = np.asarray(tensor)
599599
# If not passed, set a sensible typesize
600-
if 'cparams' in kwargs:
600+
if 'cparams' in kwargs and 'typesize' not in kwargs['cparams']:
601601
cparams = kwargs.pop('cparams')
602602
cparams = cparams.copy()
603-
if 'typesize' not in cparams:
604-
cparams['typesize'] = arr.itemsize
605-
else:
606-
cparams = {"typesize": arr.itemsize}
603+
cparams['typesize'] = arr.itemsize
604+
kwargs['cparams'] = cparams
605+
elif 'typesize' not in kwargs:
606+
kwargs['typesize'] = arr.itemsize
607607

608608
urlpath = kwargs.get('urlpath', None)
609609
contiguous = False if urlpath is None else True
@@ -615,8 +615,7 @@ def pack_tensor(tensor, chunksize=None, **kwargs):
615615
chunksize = 2 ** 28
616616
# Make that a multiple of typesize
617617
chunksize = chunksize // arr.itemsize * arr.itemsize
618-
schunk = blosc2.SChunk(chunksize=chunksize, contiguous=contiguous, data=arr,
619-
cparams=cparams, **kwargs)
618+
schunk = blosc2.SChunk(chunksize=chunksize, contiguous=contiguous, data=arr, **kwargs)
620619
# Guess the kind of tensor / array
621620
repr_tensor = repr(tensor)
622621
if "tensor" in repr_tensor:

examples/pack_tensor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
a = np.arange(1_000_000)
1414

15-
cparams = {"codec": blosc2.Codec.BLOSCLZ}
15+
cparams = {"codec": blosc2.Codec.ZSTD, "clevel": 9,
16+
"filters": [blosc2.Filter.BITSHUFFLE],
17+
}
1618
cframe = blosc2.pack_tensor(a, cparams=cparams)
1719
print("Length of packed array in bytes:", len(cframe))
1820

0 commit comments

Comments
 (0)