Skip to content

Commit 255bb1b

Browse files
authored
Merge branch 'Blosc:main' into transpose
2 parents a9b5af8 + cddb5c3 commit 255bb1b

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repos:
1616
- id: trailing-whitespace
1717

1818
- repo: https://github.com/astral-sh/ruff-pre-commit
19-
rev: v0.9.9
19+
rev: v0.11.4
2020
hooks:
2121
- id: ruff
2222
args: ["--fix", "--show-fixes"]

src/blosc2/ndarray.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,13 @@ def slice(self, key: int | slice | Sequence[slice], **kwargs: Any) -> NDArray:
18371837
>>> print(type(c))
18381838
<class 'blosc2.ndarray.NDArray'>
18391839
"""
1840-
kwargs = _check_ndarray_kwargs(**kwargs)
1840+
if "cparams" not in kwargs:
1841+
kwargs["cparams"] = {
1842+
"codec": self.cparams.codec,
1843+
"clevel": self.cparams.clevel,
1844+
"filters": self.cparams.filters,
1845+
}
1846+
kwargs = _check_ndarray_kwargs(**kwargs) # sets cparams to defaults
18411847
key, mask = process_key(key, self.shape)
18421848
start, stop, step = get_ndarray_start_stop(self.ndim, key, self.shape)
18431849
key = (start, stop)

tests/ndarray/test_slice.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ def test_slice(shape, chunks, blocks, slices, dtype):
3030
np.testing.assert_almost_equal(b[...], np_slice)
3131

3232

33+
@pytest.mark.parametrize(argnames, argvalues)
34+
def test_slice_codec_and_clevel(shape, chunks, blocks, slices, dtype):
35+
size = int(np.prod(shape))
36+
nparray = np.arange(size, dtype=dtype).reshape(shape)
37+
a = blosc2.asarray(
38+
nparray,
39+
chunks=chunks,
40+
blocks=blocks,
41+
cparams={"codec": blosc2.Codec.LZ4, "clevel": 6, "filters": [blosc2.Filter.BITSHUFFLE]},
42+
)
43+
44+
b = a.slice(slices)
45+
assert b.cparams.codec == a.cparams.codec
46+
assert b.cparams.clevel == a.cparams.clevel
47+
assert b.cparams.filters == a.cparams.filters
48+
49+
3350
argnames = "shape, chunks, blocks, slices, dtype, chunks2, blocks2"
3451
argvalues = [
3552
([456], [258], [73], slice(0, 1), np.int32, [1], [1]),

0 commit comments

Comments
 (0)