Skip to content

Commit 53b1a5d

Browse files
author
Luke Shaw
committed
Edited slice to recompress with original data cparams
1 parent 6e23c22 commit 53b1a5d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/blosc2/ndarray.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1839,8 +1839,13 @@ def slice(self, key: int | slice | Sequence[slice], **kwargs: Any) -> NDArray:
18391839
"""
18401840
original_codec = self.cparams.codec
18411841
original_clevel = self.cparams.clevel
1842+
original_filters = self.cparams.filters
18421843
if "cparams" not in kwargs:
1843-
kwargs["cparams"] = {"codec": original_codec, "clevel": original_clevel}
1844+
kwargs["cparams"] = {
1845+
"codec": original_codec,
1846+
"clevel": original_clevel,
1847+
"filters": original_filters,
1848+
}
18441849
kwargs = _check_ndarray_kwargs(**kwargs) # sets cparams to defaults
18451850
key, mask = process_key(key, self.shape)
18461851
start, stop, step = get_ndarray_start_stop(self.ndim, key, self.shape)

tests/ndarray/test_slice.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ def test_slice_codec_and_clevel(shape, chunks, blocks, slices, dtype):
3535
size = int(np.prod(shape))
3636
nparray = np.arange(size, dtype=dtype).reshape(shape)
3737
a = blosc2.asarray(
38-
nparray, chunks=chunks, blocks=blocks, cparams={"codec": blosc2.Codec.LZ4, "clevel": 6}
38+
nparray,
39+
chunks=chunks,
40+
blocks=blocks,
41+
cparams={"codec": blosc2.Codec.LZ4, "clevel": 6, "filters": [blosc2.Filter.BITSHUFFLE]},
3942
)
4043

4144
b = a.slice(slices)
4245
assert b.cparams.codec == a.cparams.codec
4346
assert b.cparams.clevel == a.cparams.clevel
47+
assert b.cparams.filters == a.cparams.filters
4448

4549

4650
argnames = "shape, chunks, blocks, slices, dtype, chunks2, blocks2"

0 commit comments

Comments
 (0)