Miscellaneous¶
This page documents the miscellaneous members of the blosc2
module that do not fit into other categories.
- class blosc2.LazyExpr(new_op)[source]¶
Class for hosting lazy expressions.
This is not meant to be called directly from user space.
Once the lazy expression is created, it can be evaluated via
LazyExpr.compute()
.- Attributes:
Methods
compute
([item])Return an NDArray containing the evaluation of the LazyArray.
get_chunk
(nchunk)Get the nchunk of the expression, evaluating only that one.
indices
([order])Return an LazyArray containing the indices where self is True.
sort
([order])Return a sorted LazyArray.
to_cframe
()Compute LazyArray and convert to cframe.
get_num_elements
slice
update_expr
- compute(item=None, **kwargs) NDArray [source]¶
Return an NDArray containing the evaluation of the LazyArray.
- Parameters:
item¶ (slice, list of slices, optional) – If provided, item is used to slice the operands prior to computation; not to retrieve specified slices of the evaluated result. This difference between slicing operands and slicing the final expression is important when reductions or a where clause are used in the expression.
kwargs¶ (Any, optional) – Keyword arguments that are supported by the
empty()
constructor. These arguments will be set in the resulting NDArray.
- Returns:
out – A NDArray containing the result of evaluating the LazyUDF or LazyExpr.
- Return type:
Notes
If self is a LazyArray from an udf, the kwargs used to store the resulting array will be the ones passed to the constructor in
lazyudf()
(except the urlpath) updated with the kwargs passed when calling this method.
Examples
>>> import blosc2 >>> import numpy as np >>> dtype = np.float64 >>> shape = [3, 3] >>> size = shape[0] * shape[1] >>> a = np.linspace(0, 5, num=size, dtype=dtype).reshape(shape) >>> b = np.linspace(0, 5, num=size, dtype=dtype).reshape(shape) >>> # Convert numpy arrays to Blosc2 arrays >>> a1 = blosc2.asarray(a) >>> b1 = blosc2.asarray(b) >>> # Perform the mathematical operation >>> expr = a1 + b1 >>> output = expr.compute() >>> f"Result of a + b (lazy evaluation): {output[:]}" Result of a + b (lazy evaluation): [[ 0. 1.25 2.5 ] [ 3.75 5. 6.25] [ 7.5 8.75 10. ]]
- property dtype¶
Get the data type of the LazyArray.
- Returns:
out – The data type of the LazyArray.
- Return type:
np.dtype
- indices(order: str | list[str] | None = None) LazyArray [source]¶
Return an LazyArray containing the indices where self is True.
The LazyArray must be of bool dtype (e.g. a condition).
- Parameters:
order¶ (str, list of str, optional) – Specifies which fields to compare first, second, etc. A single field can be specified as a string. Not all fields need to be specified, only the ones by which the array is to be sorted.
- Returns:
out – The indices of the LazyArray self that are True.
- Return type:
- property info¶
Get information about the LazyArray.
- Returns:
out – A printable class with information about the LazyArray.
- Return type:
InfoReporter
- property ndim: int¶
Get the number of dimensions of the LazyArray.
- Returns:
out – The number of dimensions of the LazyArray.
- Return type:
int
- property shape¶
Get the shape of the LazyArray.
- Returns:
out – The shape of the LazyArray.
- Return type:
tuple
- blosc2.are_partitions_aligned(shape, chunks, blocks)[source]¶
Check if the partitions defined by chunks and blocks are aligned with the shape.
This function verifies that the shape is aligned with the chunks and the chunks are aligned with the blocks.
- Returns:
True if the partitions are aligned, False otherwise.
- Return type:
bool
- blosc2.are_partitions_behaved(shape, chunks, blocks)[source]¶
Check if the partitions defined by chunks and blocks are well-behaved with respect to the shape.
This function verifies that partitions are C-contiguous with respect the outer container.
- Returns:
True if the partitions are well-behaved, False otherwise.
- Return type:
bool
- blosc2.concatenate(arrays: list[NDArray], /, axis=0, **kwargs: Any) NDArray [source]¶
Concatenate a list of arrays along a specified axis.
This is an alias for
concat()
. It is kept for backward compatibility.
- blosc2.estore_from_cframe(cframe: bytes, copy: bool = False) EmbedStore [source]¶
Deserialize a CFrame to an EmbedStore object.
- Parameters:
- Returns:
estore – The deserialized EmbedStore object.
- Return type:
- blosc2.from_cframe(cframe: bytes | str, copy: bool = True) EmbedStore | NDArray | SChunk [source]¶
Create a EmbedStore, NDArray or SChunk instance from a contiguous frame buffer.
- Parameters:
cframe¶ (bytes or str) – The bytes object containing the in-memory cframe.
copy¶ (bool) – Whether to internally make a copy. If False, the user is responsible for keeping a reference to cframe. Default is True, which is safer. If you need to save time/memory, you can set it to False, but then you must ensure that the cframe is not garbage collected while the returned object is still in use.
- Returns:
out – A new instance of the appropriate type containing the data passed.
- Return type:
EmbedStore, NDArray or SChunk
See also
from_cframe()
,from_cframe()
,from_cframe()
- blosc2.indices(array: NDArray, order: str | list[str] | None = None, **kwargs: Any) NDArray [source]¶
Return the indices of a sorted array following the specified order.
This is only valid for 1-dim structured arrays.
- Parameters:
order¶ (str, list of str, optional) – Specifies which fields to compare first, second, etc. A single field can be specified as a string. Not all fields need to be specified, only the ones by which the array is to be sorted. If None, the array is not sorted.
kwargs¶ (Any, optional) – Keyword arguments that are supported by the
empty()
constructor.
- Returns:
out – The sorted array.
- Return type:
- blosc2.sort(array: NDArray, order: str | list[str] | None = None, **kwargs: Any) NDArray [source]¶
Return a sorted array following the specified order.
This is only valid for 1-dim structured arrays.
- Parameters:
order¶ (str, list of str, optional) – Specifies which fields to compare first, second, etc. A single field can be specified as a string. Not all fields need to be specified, only the ones by which the array is to be sorted.
kwargs¶ (Any, optional) – Keyword arguments that are supported by the
empty()
constructor.
- Returns:
out – The sorted array.
- Return type: