SChunk.__getitem__#

SChunk.__getitem__(item: int | slice) str | bytes#

Get a slice from the SChunk.

Parameters:

item (int or slice) – The index or slice for the data. Note that the step parameter is not honored.

Returns:

out – The decompressed slice as 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 than or equal to the number of items in the SChunk.

  • RunTimeError – If a problem is detected.

  • IndexError – If step is not 1.

See also

get_slice()

Examples

>>> import blosc2
>>> import numpy as np
>>> nchunks = 4
>>> chunk_size = 200 * 1000 * 4
>>> data = np.arange(nchunks * chunk_size // 4, dtype=np.int32)
>>> cparams = blosc2.CParams(typesize=4)
>>> schunk = blosc2.SChunk(chunksize=chunk_size, data=data, cparams=cparams)
>>> # 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]