SChunk.__getitem__#
- SChunk.__getitem__(item: int | slice) str | bytes #
Get a slice from the SChunk.
- Parameters:
item¶ (int or slice) – The index for the slice. Note that the step parameter is not honored.
- Returns:
out – The decompressed slice in form of a Python str or bytes object.
- Return type:
str or bytes
- Raises:
ValueError – If the size to get is negative. If
item
.start is greater or equal than the SChunk nitemsRunTimeError – If some problem was detected.
IndexError – If step is not 1.
See also
Examples
>>> import blosc2 >>> import numpy as np >>> nchunks = 4 >>> chunk_size = 200 * 1000 * 4 >>> data = np.arange(nchunks * chunk_size // 4, dtype=np.int32) >>> schunk = blosc2.SChunk(chunksize=chunk_size, data=data, cparams={"typesize": 4}) >>> # Use __getitem__ to retrieve the same slice of data from the SChunk >>> res = schunk[150:155] >>> f"Slice data: {np.frombuffer(res, dtype=np.int32)}" Slice data: [150 151 152 153 154]