From 31c4c0ba154c0e0cbca556c02903147df46cc7ca Mon Sep 17 00:00:00 2001 From: Francesc Alted Date: Sat, 27 Sep 2025 14:51:34 +0200 Subject: [PATCH 1/7] Preliminary version of the Array protocol --- src/blosc2/__init__.py | 1 + src/blosc2/lazyexpr.py | 32 ++- src/blosc2/ndarray.py | 460 +++++++++++++++++++++-------------------- 3 files changed, 249 insertions(+), 244 deletions(-) diff --git a/src/blosc2/__init__.py b/src/blosc2/__init__.py index 01bd8bd5..bc8794cb 100644 --- a/src/blosc2/__init__.py +++ b/src/blosc2/__init__.py @@ -392,6 +392,7 @@ def _raise(exc): ) from .ndarray import ( + Array, NDArray, NDField, Operand, diff --git a/src/blosc2/lazyexpr.py b/src/blosc2/lazyexpr.py index 6a51b2ed..70044ed3 100644 --- a/src/blosc2/lazyexpr.py +++ b/src/blosc2/lazyexpr.py @@ -286,7 +286,7 @@ def sort(self, order: str | list[str] | None = None) -> blosc2.LazyArray: pass @abstractmethod - def compute(self, item: slice | list[slice] | None = None, **kwargs: Any) -> blosc2.NDArray: + def compute(self, item: slice | list[slice] | None = None, **kwargs: Any) -> blosc2.Array: """ Return an :ref:`NDArray` containing the evaluation of the :ref:`LazyArray`. @@ -337,7 +337,7 @@ def compute(self, item: slice | list[slice] | None = None, **kwargs: Any) -> blo pass @abstractmethod - def __getitem__(self, item: int | slice | Sequence[slice]) -> blosc2.NDArray: + def __getitem__(self, item: int | slice | Sequence[slice]) -> blosc2.Array: """ Return a NumPy.ndarray containing the evaluation of the :ref:`LazyArray`. @@ -507,14 +507,12 @@ def convert_inputs(inputs): return [] inputs_ = [] for obj in inputs: - if not isinstance( - obj, np.ndarray | blosc2.NDArray | blosc2.NDField | blosc2.C2Array - ) and not np.isscalar(obj): + if not isinstance(obj, np.ndarray | blosc2.Array) and not np.isscalar(obj): try: obj = np.asarray(obj) except Exception: print( - "Inputs not being np.ndarray, NDArray, NDField, C2Array or Python scalar objects" + "Inputs not being np.ndarray, Array or Python scalar objects" " should be convertible to np.ndarray." ) raise @@ -687,9 +685,9 @@ def visit_Call(self, node): def conserve_functions( # noqa: C901 expression: str, - operands_old: dict[str, blosc2.NDArray | blosc2.LazyExpr], - operands_new: dict[str, blosc2.NDArray | blosc2.LazyExpr], -) -> tuple[str, dict[str, blosc2.NDArray]]: + operands_old: dict[str, blosc2.Array], + operands_new: dict[str, blosc2.Array], +) -> tuple[str, dict[str, blosc2.Array]]: """ Given an expression in string form, return its operands. @@ -1154,7 +1152,7 @@ def fast_eval( # noqa: C901 operands: dict, getitem: bool, **kwargs, -) -> blosc2.NDArray | np.ndarray: +) -> blosc2.Array | np.ndarray: """Evaluate the expression in chunks of operands using a fast path. Parameters @@ -1321,7 +1319,7 @@ def slices_eval( # noqa: C901 getitem: bool, _slice=NDINDEX_EMPTY_TUPLE, **kwargs, -) -> blosc2.NDArray | np.ndarray: +) -> blosc2.Array | np.ndarray: """Evaluate the expression in chunks of operands. This function can handle operands with different chunk shapes and @@ -1724,7 +1722,7 @@ def reduce_slices( # noqa: C901 reduce_args, _slice=NDINDEX_EMPTY_TUPLE, **kwargs, -) -> blosc2.NDArray | np.ndarray: +) -> blosc2.Array | np.ndarray: """Evaluate the expression in chunks of operands. This function can handle operands with different chunk shapes. @@ -2969,7 +2967,7 @@ def sort(self, order: str | list[str] | None = None) -> blosc2.LazyArray: lazy_expr._order = order return lazy_expr - def compute(self, item=(), **kwargs) -> blosc2.NDArray: + def compute(self, item=(), **kwargs) -> blosc2.Array: # When NumPy ufuncs are called, the user may add an `out` parameter to kwargs if "out" in kwargs: kwargs["_output"] = kwargs.pop("out") @@ -3252,7 +3250,7 @@ def info(self): def info_items(self): inputs = {} for key, value in self.inputs_dict.items(): - if isinstance(value, np.ndarray | blosc2.NDArray | blosc2.C2Array): + if isinstance(value, np.ndarray | blosc2.Array | blosc2.C2Array): inputs[key] = f"<{value.__class__.__name__}> {value.shape} {value.dtype}" else: inputs[key] = str(value) @@ -3484,7 +3482,7 @@ def seek_operands(names, local_dict=None, global_dict=None, _frame_depth: int = def lazyexpr( expression: str | bytes | LazyExpr | blosc2.NDArray, operands: dict | None = None, - out: blosc2.NDArray | np.ndarray = None, + out: blosc2.Array | np.ndarray = None, where: tuple | list | None = None, local_dict: dict | None = None, global_dict: dict | None = None, @@ -3633,9 +3631,9 @@ def evaluate( ex: str, local_dict: dict | None = None, global_dict: dict | None = None, - out: np.ndarray | blosc2.NDArray = None, + out: np.ndarray | blosc2.Array = None, **kwargs: Any, -) -> np.ndarray | blosc2.NDArray: +) -> np.ndarray | blosc2.Array: """ Evaluate a string expression using the Blosc2 compute engine. diff --git a/src/blosc2/ndarray.py b/src/blosc2/ndarray.py index 722db50b..3c0b378b 100644 --- a/src/blosc2/ndarray.py +++ b/src/blosc2/ndarray.py @@ -16,7 +16,7 @@ from collections import OrderedDict, namedtuple from functools import reduce from itertools import product -from typing import TYPE_CHECKING, Any, NamedTuple +from typing import TYPE_CHECKING, Any, NamedTuple, Protocol, runtime_checkable from numpy.exceptions import ComplexWarning @@ -38,6 +38,30 @@ NUMPY_GE_2_0 = np.__version__ >= "2.0" +@runtime_checkable +class Array(Protocol): + """ + A typing protocol for array-like objects with basic array interface. + + This protocol defines the minimal interface that array-like objects + must implement to be compatible with blosc2 functions. + """ + + @property + def dtype(self) -> Any: + """The data type of the array.""" + ... + + @property + def shape(self) -> tuple[int, ...]: + """The shape of the array.""" + ... + + def __getitem__(self, key: Any) -> Any: + """Get items from the array.""" + ... + + def is_documented_by(original): def wrapper(target): target.__doc__ = original.__doc__ @@ -264,7 +288,7 @@ def get_flat_slices( def reshape( - src: NDArray | NDField | blosc2.LazyArray | blosc2.C2Array, + src: blosc2.Array, shape: tuple | list, c_order: bool = True, **kwargs: Any, @@ -370,23 +394,13 @@ def reshape( def _check_allowed_dtypes( - value: bool - | int - | float - | str - | blosc2.NDArray - | blosc2.NDField - | blosc2.C2Array - | blosc2.Proxy - | blosc2.LazyExpr, + value: bool | int | float | str | blosc2.Array | blosc2.Proxy | blosc2.LazyExpr, ): if not ( isinstance( value, blosc2.LazyExpr - | blosc2.NDArray - | blosc2.NDField - | blosc2.C2Array + | blosc2.Array | blosc2.Proxy | blosc2.ProxyNDField | blosc2.SimpleProxy @@ -395,18 +409,18 @@ def _check_allowed_dtypes( or np.isscalar(value) ): raise RuntimeError( - "Expected LazyExpr, NDArray, NDField, C2Array, Proxy, np.ndarray or scalar instances" + "Expected LazyExpr, Array, Proxy, np.ndarray or scalar instances" f" and you provided a '{type(value)}' instance" ) def sum( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, dtype: np.dtype | str = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | int | float | complex | bool: +) -> np.ndarray | blosc2.Array | int | float | complex | bool: """ Return the sum of array elements over a given axis. @@ -458,12 +472,12 @@ def sum( def mean( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, dtype: np.dtype | str = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | int | float | complex | bool: +) -> np.ndarray | blosc2.Array | int | float | complex | bool: """ Return the arithmetic mean along the specified axis. @@ -494,13 +508,13 @@ def mean( def std( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, dtype: np.dtype | str = None, ddof: int = 0, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | int | float | bool: +) -> np.ndarray | blosc2.Array | int | float | bool: """ Return the standard deviation along the specified axis. @@ -553,13 +567,13 @@ def std( def var( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, dtype: np.dtype | str = None, ddof: int = 0, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | int | float | bool: +) -> np.ndarray | blosc2.Array | int | float | bool: """ Return the variance along the specified axis. @@ -595,12 +609,12 @@ def var( def prod( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, dtype: np.dtype | str = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | int | float | complex | bool: +) -> np.ndarray | blosc2.Array | int | float | complex | bool: """ Return the product of array elements over a given axis. @@ -635,11 +649,11 @@ def prod( def min( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | int | float | complex | bool: +) -> np.ndarray | blosc2.Array | int | float | complex | bool: """ Return the minimum along a given axis. @@ -683,11 +697,11 @@ def min( def max( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | int | float | complex | bool: +) -> np.ndarray | blosc2.Array | int | float | complex | bool: """ Return the maximum along a given axis. @@ -726,11 +740,11 @@ def max( def any( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | bool: +) -> np.ndarray | blosc2.Array | bool: """ Test whether any array element along a given axis evaluates to True. @@ -767,11 +781,11 @@ def any( def all( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | bool: +) -> np.ndarray | blosc2.Array | bool: """ Test whether all array elements along a given axis evaluate to True. @@ -800,7 +814,7 @@ def all( return ndarr.all(axis=axis, keepdims=keepdims, **kwargs) -def sin(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def sin(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the trigonometric sine, element-wise. @@ -835,7 +849,7 @@ def sin(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc return blosc2.LazyExpr(new_op=(ndarr, "sin", None)) -def cos(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def cos(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Trigonometric cosine, element-wise. @@ -870,7 +884,7 @@ def cos(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc return blosc2.LazyExpr(new_op=(ndarr, "cos", None)) -def tan(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def tan(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the trigonometric tangent, element-wise. @@ -906,7 +920,7 @@ def tan(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc return blosc2.LazyExpr(new_op=(ndarr, "tan", None)) -def sqrt(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def sqrt(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return the non-negative square-root of an array, element-wise. @@ -941,7 +955,7 @@ def sqrt(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blos return blosc2.LazyExpr(new_op=(ndarr, "sqrt", None)) -def sinh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def sinh(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Hyperbolic sine, element-wise. @@ -976,7 +990,7 @@ def sinh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blos return blosc2.LazyExpr(new_op=(ndarr, "sinh", None)) -def cosh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def cosh(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the hyperbolic cosine, element-wise. @@ -1011,7 +1025,7 @@ def cosh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blos return blosc2.LazyExpr(new_op=(ndarr, "cosh", None)) -def tanh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def tanh(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the hyperbolic tangent, element-wise. @@ -1046,7 +1060,7 @@ def tanh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blos return blosc2.LazyExpr(new_op=(ndarr, "tanh", None)) -def arcsin(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def arcsin(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the inverse sine, element-wise. @@ -1084,7 +1098,7 @@ def arcsin(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> bl asin = arcsin # alias -def arccos(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def arccos(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the inverse cosine, element-wise. @@ -1122,7 +1136,7 @@ def arccos(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> bl acos = arccos # alias -def arctan(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def arctan(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the inverse tangent, element-wise. @@ -1160,9 +1174,7 @@ def arctan(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> bl atan = arctan # alias -def arctan2( - ndarr1: NDArray | NDField | blosc2.C2Array, ndarr2: NDArray | NDField | blosc2.C2Array, / -) -> blosc2.LazyExpr: +def arctan2(ndarr1: blosc2.Array, ndarr2: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the element-wise arc tangent of ``ndarr1 / ndarr2`` choosing the quadrant correctly. @@ -1206,7 +1218,7 @@ def arctan2( atan2 = arctan2 # alias -def arcsinh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def arcsinh(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the inverse hyperbolic sine, element-wise. @@ -1244,7 +1256,7 @@ def arcsinh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> b asinh = arcsinh # alias -def arccosh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def arccosh(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the inverse hyperbolic cosine, element-wise. @@ -1282,7 +1294,7 @@ def arccosh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> b acosh = arccosh # alias -def arctanh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def arctanh(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the inverse hyperbolic tangent, element-wise. @@ -1320,7 +1332,7 @@ def arctanh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> b atanh = arctanh # alias -def exp(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def exp(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Calculate the exponential of all elements in the input array. @@ -1355,7 +1367,7 @@ def exp(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc return blosc2.LazyExpr(new_op=(ndarr, "exp", None)) -def expm1(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def expm1(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Calculate ``exp(ndarr) - 1`` for all elements in the array. @@ -1390,7 +1402,7 @@ def expm1(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blo return blosc2.LazyExpr(new_op=(ndarr, "expm1", None)) -def log(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def log(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the natural logarithm, element-wise. @@ -1424,7 +1436,7 @@ def log(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc return blosc2.LazyExpr(new_op=(ndarr, "log", None)) -def log10(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def log10(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return the base 10 logarithm of the input array, element-wise. @@ -1458,7 +1470,7 @@ def log10(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blo return blosc2.LazyExpr(new_op=(ndarr, "log10", None)) -def log1p(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def log1p(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return the natural logarithm of one plus the input array, element-wise. @@ -1492,7 +1504,7 @@ def log1p(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blo return blosc2.LazyExpr(new_op=(ndarr, "log1p", None)) -def log2(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def log2(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return the base 2 logarithm of the input array, element-wise. @@ -1514,7 +1526,7 @@ def log2(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blos return blosc2.LazyExpr(new_op=(ndarr, "log2", None)) -def conj(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def conj(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return the complex conjugate, element-wise. @@ -1548,7 +1560,7 @@ def conj(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blos return blosc2.LazyExpr(new_op=(ndarr, "conj", None)) -def real(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def real(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return the real part of the complex array, element-wise. @@ -1582,7 +1594,7 @@ def real(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blos return blosc2.LazyExpr(new_op=(ndarr, "real", None)) -def imag(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def imag(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return the imaginary part of the complex array, element-wise. @@ -1616,9 +1628,7 @@ def imag(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blos return blosc2.LazyExpr(new_op=(ndarr, "imag", None)) -def contains( - ndarr: NDArray | NDField | blosc2.C2Array, value: str | bytes | NDArray | NDField | blosc2.C2Array, / -) -> blosc2.LazyExpr: +def contains(ndarr: blosc2.Array, value: str | bytes | blosc2.Array, /) -> blosc2.LazyExpr: """ Check if the array contains a specified value. @@ -1652,7 +1662,7 @@ def contains( return blosc2.LazyExpr(new_op=(ndarr, "contains", value)) -def abs(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def abs(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Calculate the absolute value element-wise. @@ -1686,7 +1696,7 @@ def abs(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc return blosc2.LazyExpr(new_op=(ndarr, "abs", None)) -def isnan(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def isnan(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return True/False for not-a-number values element-wise. @@ -1718,7 +1728,7 @@ def isnan(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blo return blosc2.LazyExpr(new_op=(ndarr, "isnan", None)) -def isfinite(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def isfinite(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return True/False for finite values element-wise. @@ -1750,7 +1760,7 @@ def isfinite(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> return blosc2.LazyExpr(new_op=(ndarr, "isfinite", None)) -def isinf(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def isinf(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return True/False for infinite values element-wise. @@ -1782,7 +1792,7 @@ def isinf(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blo return blosc2.LazyExpr(new_op=(ndarr, "isinf", None)) -# def nonzero(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +# def nonzero(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: # """ # Return indices of nonzero values. @@ -1804,9 +1814,7 @@ def isinf(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blo # return ndarr.__ne__(0) -def count_nonzero( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, axis: int | Sequence[int] | None = None -) -> int: +def count_nonzero(ndarr: blosc2.Array, axis: int | Sequence[int] | None = None) -> int: """ Return number of nonzero values along axes. @@ -1832,8 +1840,8 @@ def count_nonzero( def equal( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the truth value of x1_i == x2_i for each element x1_i of the input array x1 @@ -1841,10 +1849,10 @@ def equal( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -1860,8 +1868,8 @@ def equal( def not_equal( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the truth value of x1_i != x2_i for each element x1_i of the input array x1 @@ -1869,10 +1877,10 @@ def not_equal( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -1888,8 +1896,8 @@ def not_equal( def less_equal( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the truth value of x1_i <= x2_i for each element x1_i of the input array x1 @@ -1897,10 +1905,10 @@ def less_equal( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -1916,8 +1924,8 @@ def less_equal( def less( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the truth value of x1_i < x2_i for each element x1_i of the input array x1 @@ -1925,10 +1933,10 @@ def less( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -1944,8 +1952,8 @@ def less( def greater_equal( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the truth value of x1_i >= x2_i for each element x1_i of the input array x1 @@ -1953,10 +1961,10 @@ def greater_equal( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -1972,8 +1980,8 @@ def greater_equal( def greater( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the truth value of x1_i > x2_i for each element x1_i of the input array x1 @@ -1981,10 +1989,10 @@ def greater( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -2000,8 +2008,8 @@ def greater( def multiply( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the value of x1_i * x2_i for each element x1_i of the input array x1 @@ -2009,10 +2017,10 @@ def multiply( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -2028,8 +2036,8 @@ def multiply( def divide( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the value of x1_i / x2_i for each element x1_i of the input array x1 @@ -2037,10 +2045,10 @@ def divide( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -2056,8 +2064,8 @@ def divide( def nextafter( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Returns the next representable floating-point value for each element x1_i of the input @@ -2065,10 +2073,10 @@ def nextafter( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. Real-valued floating point dtype. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1 and have same data type. Returns @@ -2084,8 +2092,8 @@ def nextafter( def hypot( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the square root of the sum of squares for each element x1_i of the input array @@ -2093,10 +2101,10 @@ def hypot( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. Real-valued floating point dtype. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. Real-valued floating point dtype. Returns @@ -2112,8 +2120,8 @@ def hypot( def copysign( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Composes a floating-point value with the magnitude of x1_i and the sign of x2_i @@ -2121,10 +2129,10 @@ def copysign( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. Real-valued floating point dtype. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. Real-valued floating point dtype. Returns @@ -2140,8 +2148,8 @@ def copysign( def maximum( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the maximum value for each element x1_i of the input array x1 relative to the @@ -2149,10 +2157,10 @@ def maximum( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. Real-valued dtype. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. Real-valued dtype. Returns @@ -2168,8 +2176,8 @@ def maximum( def minimum( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the minimum value for each element x1_i of the input array x1 relative to the @@ -2177,10 +2185,10 @@ def minimum( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. Real-valued dtype. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. Real-valued dtype. Returns @@ -2195,13 +2203,13 @@ def minimum( return blosc2.LazyExpr(new_op=(x1, "minimum", x2)) -def reciprocal(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.LazyExpr: +def reciprocal(x: blosc2.Array) -> blosc2.LazyExpr: """ Computes the value of 1/x1_i for each element x1_i of the input array x1. Parameters ---------- - x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x: blosc2.Array First input array, floating-point data type. Returns @@ -2216,14 +2224,14 @@ def reciprocal(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc return 1.0 / x -def floor(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.LazyExpr: +def floor(x: blosc2.Array) -> blosc2.LazyExpr: """ Rounds each element x_i of the input array x to the greatest (i.e., closest to +infinity) integer-valued number that is not greater than x_i. Parameters ---------- - x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x: blosc2.Array First input array. May have any real-valued data type. Returns @@ -2238,14 +2246,14 @@ def floor(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.Laz return blosc2.LazyExpr(new_op=(x, "floor", None)) -def ceil(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.LazyExpr: +def ceil(x: blosc2.Array) -> blosc2.LazyExpr: """ Rounds each element x_i of the input array x to the smallest (i.e., closest to -infinity) integer-valued number that is not smaller than x_i. Parameters ---------- - x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x: blosc2.Array First input array. May have any real-valued data type. Returns @@ -2260,14 +2268,14 @@ def ceil(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.Lazy return blosc2.LazyExpr(new_op=(x, "ceil", None)) -def trunc(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.LazyExpr: +def trunc(x: blosc2.Array) -> blosc2.LazyExpr: """ Rounds each element x_i of the input array x to the closest to 0 integer-valued number. Parameters ---------- - x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x: blosc2.Array First input array. May have any real-valued data type. Returns @@ -2282,7 +2290,7 @@ def trunc(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.Laz return blosc2.LazyExpr(new_op=(x, "trunc", None)) -def signbit(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.LazyExpr: +def signbit(x: blosc2.Array) -> blosc2.LazyExpr: """ Determines whether the sign bit is set for each element x_i of the input array x. @@ -2291,7 +2299,7 @@ def signbit(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.L Parameters ---------- - x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x: blosc2.Array First input array. May have any real-valued floating-point data type. Returns @@ -2306,13 +2314,13 @@ def signbit(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.L return blosc2.LazyExpr(new_op=(x, "signbit", None)) -def sign(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.LazyExpr: +def sign(x: blosc2.Array) -> blosc2.LazyExpr: """ Returns an indication of the sign of a number for each element x_i of the input array x. Parameters ---------- - x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x: blosc2.Array First input array. May have any numeric data type. Returns @@ -2327,13 +2335,13 @@ def sign(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.Lazy return blosc2.LazyExpr(new_op=(x, "sign", None)) -def round(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.LazyExpr: +def round(x: blosc2.Array) -> blosc2.LazyExpr: """ Rounds each element x_i of the input array x to the nearest integer-valued number. Parameters ---------- - x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x: blosc2.Array First input array. May have any numeric data type. Returns @@ -2349,8 +2357,8 @@ def round(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.Laz def floor_divide( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the value of x1_i // x2_i for each element x1_i of the input array x1 @@ -2358,10 +2366,10 @@ def floor_divide( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any real-valued data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any real-valued data type. Returns @@ -2377,8 +2385,8 @@ def floor_divide( def add( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the value of x1_i + x2_i for each element x1_i of the input array x1 @@ -2386,10 +2394,10 @@ def add( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -2405,8 +2413,8 @@ def add( def subtract( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the value of x1_i - x2_i for each element x1_i of the input array x1 @@ -2414,10 +2422,10 @@ def subtract( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -2432,13 +2440,13 @@ def subtract( return x1 - x2 -def square(x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.LazyExpr: +def square(x1: blosc2.Array) -> blosc2.LazyExpr: """ Computes the value of x1_i**2 for each element x1_i of the input array x1. Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. Returns @@ -2454,8 +2462,8 @@ def square(x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.L def pow( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of x1_i**x2_i for each element x1_i of the input array x1 and x2_i @@ -2463,10 +2471,10 @@ def pow( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -2482,8 +2490,8 @@ def pow( def logical_xor( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of x1_i ^ x2_i for each element x1_i of the input array x1 and x2_i @@ -2491,10 +2499,10 @@ def logical_xor( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array, boolean. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1, boolean. Returns @@ -2512,8 +2520,8 @@ def logical_xor( def logical_and( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of x1_i & x2_i for each element x1_i of the input array x1 and x2_i @@ -2521,10 +2529,10 @@ def logical_and( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array, boolean. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. Boolean. Returns @@ -2542,8 +2550,8 @@ def logical_and( def logical_or( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of x1_i | x2_i for each element x1_i of the input array x1 and x2_i @@ -2551,10 +2559,10 @@ def logical_or( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array, boolean. - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2: blosc2.Array Second input array. Must be compatible with x1, boolean. Returns @@ -2572,14 +2580,14 @@ def logical_or( def logical_not( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of ~x1_i for each element x1_i of the input array x1. Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array Input array, boolean. Returns @@ -2597,8 +2605,8 @@ def logical_not( def bitwise_xor( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of x1_i ^ x2_i for each element x1_i of the input array x1 and x2_i @@ -2606,10 +2614,10 @@ def bitwise_xor( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array, integer or boolean. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1, integer or boolean. Returns @@ -2625,8 +2633,8 @@ def bitwise_xor( def bitwise_and( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of x1_i & x2_i for each element x1_i of the input array x1 and x2_i @@ -2634,10 +2642,10 @@ def bitwise_and( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array, integer or boolean. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. Integer or boolean. Returns @@ -2653,8 +2661,8 @@ def bitwise_and( def bitwise_or( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of x1_i | x2_i for each element x1_i of the input array x1 and x2_i @@ -2662,10 +2670,10 @@ def bitwise_or( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array, integer or boolean. - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2: blosc2.Array Second input array. Must be compatible with x1, integer or boolean. Returns @@ -2681,14 +2689,14 @@ def bitwise_or( def bitwise_invert( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of ~x1_i for each element x1_i of the input array x1. Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array Input array, integer or boolean. Returns @@ -2704,8 +2712,8 @@ def bitwise_invert( def bitwise_right_shift( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Shifts the bits of each element x1_i of the input array x1 to the right according to @@ -2716,10 +2724,10 @@ def bitwise_right_shift( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array, integer. - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2: blosc2.Array Second input array. Must be compatible with x1, integer. Returns ------- @@ -2734,8 +2742,8 @@ def bitwise_right_shift( def bitwise_left_shift( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Shifts the bits of each element x1_i of the input array x1 to the left by appending x2_i @@ -2745,10 +2753,10 @@ def bitwise_left_shift( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array, integer. - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2: blosc2.Array Second input array. Must be compatible with x1, integer. Returns @@ -2764,14 +2772,14 @@ def bitwise_left_shift( def positive( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the numerical positive of each element x_i (i.e., out_i = +x_i) of the input array x. Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. Returns @@ -2787,14 +2795,14 @@ def positive( def negative( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the numerical negative of each element x_i (i.e., out_i = -x_i) of the input array x. Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. Returns @@ -2810,8 +2818,8 @@ def negative( def remainder( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Returns the remainder of division for each element x1_i of the input array x1 and the @@ -2821,10 +2829,10 @@ def remainder( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2: blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -2880,10 +2888,10 @@ def logaddexp(x1: int | float | NDArray, x2: int | float | NDArray) -> NDArray: Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any real-valued floating-point data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any real-valued floating-point data type. @@ -3063,13 +3071,13 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): return NotImplemented # if not implemented in numexpr will default to NumPy - def __add__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __add__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) if blosc2.result_type(value, self) == blosc2.bool_: return blosc2.LazyExpr(new_op=(value, "|", self)) return blosc2.LazyExpr(new_op=(self, "+", value)) - def __iadd__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __iadd__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: return self.__add__(value) @is_documented_by(negative) @@ -3084,86 +3092,86 @@ def __pos__(self) -> blosc2.LazyExpr: def __mod__(self, other) -> blosc2.LazyExpr: return remainder(self, other) - def __radd__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __radd__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: return self.__add__(value) - def __sub__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __sub__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "-", value)) - def __isub__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __isub__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "-", value)) - def __rsub__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __rsub__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(value, "-", self)) @is_documented_by(multiply) - def __mul__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __mul__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) # catch special case of multiplying two bools (not implemented in numexpr) if blosc2.result_type(value, self) == blosc2.bool_: return blosc2.LazyExpr(new_op=(value, "&", self)) return blosc2.LazyExpr(new_op=(self, "*", value)) - def __imul__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __imul__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: return self.__mul__(value) - def __rmul__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __rmul__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: return self.__mul__(value) - def __truediv__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __truediv__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "/", value)) - def __itruediv__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __itruediv__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: return self.__truediv__(value) - def __rtruediv__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __rtruediv__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(value, "/", self)) @is_documented_by(floor_divide) - def __floordiv__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __floordiv__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "//", value)) - def __lt__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __lt__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "<", value)) - def __le__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __le__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "<=", value)) - def __gt__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __gt__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, ">", value)) - def __ge__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __ge__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, ">=", value)) - def __eq__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /): + def __eq__(self, value: int | float | blosc2.Array, /): _check_allowed_dtypes(value) if blosc2._disable_overloaded_equal: return self is value return blosc2.LazyExpr(new_op=(self, "==", value)) - def __ne__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __ne__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "!=", value)) - def __pow__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __pow__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "**", value)) - def __ipow__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __ipow__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "**", value)) - def __rpow__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __rpow__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(value, "**", self)) @@ -3172,7 +3180,7 @@ def __abs__(self) -> blosc2.LazyExpr: return abs(self) @is_documented_by(bitwise_and) - def __and__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __and__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "&", value)) @@ -5553,9 +5561,7 @@ def save(array: NDArray, urlpath: str, contiguous=True, **kwargs: Any) -> None: array.save(urlpath, contiguous, **kwargs) -def asarray( - array: Sequence | np.ndarray | blosc2.C2Array | NDArray, copy: bool | None = None, **kwargs: Any -) -> NDArray: +def asarray(array: Sequence | np.ndarray | blosc2.Array, copy: bool | None = None, **kwargs: Any) -> NDArray: """Convert the `array` to an `NDArray`. Parameters @@ -5658,7 +5664,7 @@ def asarray( def astype( - array: Sequence | np.ndarray | NDArray | blosc2.C2Array, + array: Sequence | np.ndarray | blosc2.Array, dtype, casting: str = "unsafe", copy: bool = True, @@ -5669,7 +5675,7 @@ def astype( Parameters ---------- - array: Sequence | np.ndarray | NDArray | blosc2.C2Array + array: Sequence | np.ndarray | blosc2.Array The array to be cast to a different type. dtype: DType-like The desired data type to cast to. From f5b6cb88724c09d76226263fe834b1ee8f2942e9 Mon Sep 17 00:00:00 2001 From: Francesc Alted Date: Sat, 27 Sep 2025 15:03:21 +0200 Subject: [PATCH 2/7] [WIP] More type changing --- src/blosc2/dict_store.py | 2 +- src/blosc2/embed_store.py | 2 +- src/blosc2/lazyexpr.py | 16 ++++++++-------- src/blosc2/linalg.py | 6 +++--- src/blosc2/ndarray.py | 34 +++++++++++++++++----------------- src/blosc2/tree_store.py | 9 ++++++--- 6 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/blosc2/dict_store.py b/src/blosc2/dict_store.py index 48c421b5..bb104080 100644 --- a/src/blosc2/dict_store.py +++ b/src/blosc2/dict_store.py @@ -214,7 +214,7 @@ def estore(self) -> EmbedStore: """Access the underlying EmbedStore.""" return self._estore - def __setitem__(self, key: str, value: np.ndarray | blosc2.NDArray | SChunk | C2Array) -> None: + def __setitem__(self, key: str, value: blosc2.Array | SChunk) -> None: """Add a node to the DictStore.""" if isinstance(value, np.ndarray): value = blosc2.asarray(value, cparams=self.cparams, dparams=self.dparams) diff --git a/src/blosc2/embed_store.py b/src/blosc2/embed_store.py index b876d7dc..61dd3447 100644 --- a/src/blosc2/embed_store.py +++ b/src/blosc2/embed_store.py @@ -159,7 +159,7 @@ def _ensure_capacity(self, needed_bytes: int) -> None: new_size = max(required_size, int(self._store.shape[0] * 1.5)) self._store.resize((new_size,)) - def __setitem__(self, key: str, value: np.ndarray | blosc2.NDArray | SChunk | C2Array) -> None: + def __setitem__(self, key: str, value: blosc2.Array | SChunk) -> None: """Add a node to the embed store.""" if self.mode == "r": raise ValueError("Cannot set items in read-only mode.") diff --git a/src/blosc2/lazyexpr.py b/src/blosc2/lazyexpr.py index 70044ed3..379ee934 100644 --- a/src/blosc2/lazyexpr.py +++ b/src/blosc2/lazyexpr.py @@ -507,7 +507,7 @@ def convert_inputs(inputs): return [] inputs_ = [] for obj in inputs: - if not isinstance(obj, np.ndarray | blosc2.Array) and not np.isscalar(obj): + if not isinstance(obj, blosc2.Array) and not np.isscalar(obj): try: obj = np.asarray(obj) except Exception: @@ -1152,7 +1152,7 @@ def fast_eval( # noqa: C901 operands: dict, getitem: bool, **kwargs, -) -> blosc2.Array | np.ndarray: +) -> blosc2.Array: """Evaluate the expression in chunks of operands using a fast path. Parameters @@ -1319,7 +1319,7 @@ def slices_eval( # noqa: C901 getitem: bool, _slice=NDINDEX_EMPTY_TUPLE, **kwargs, -) -> blosc2.Array | np.ndarray: +) -> blosc2.Array: """Evaluate the expression in chunks of operands. This function can handle operands with different chunk shapes and @@ -1722,7 +1722,7 @@ def reduce_slices( # noqa: C901 reduce_args, _slice=NDINDEX_EMPTY_TUPLE, **kwargs, -) -> blosc2.Array | np.ndarray: +) -> blosc2.Array: """Evaluate the expression in chunks of operands. This function can handle operands with different chunk shapes. @@ -3250,7 +3250,7 @@ def info(self): def info_items(self): inputs = {} for key, value in self.inputs_dict.items(): - if isinstance(value, np.ndarray | blosc2.Array | blosc2.C2Array): + if isinstance(value, blosc2.Array | blosc2.C2Array): inputs[key] = f"<{value.__class__.__name__}> {value.shape} {value.dtype}" else: inputs[key] = str(value) @@ -3482,7 +3482,7 @@ def seek_operands(names, local_dict=None, global_dict=None, _frame_depth: int = def lazyexpr( expression: str | bytes | LazyExpr | blosc2.NDArray, operands: dict | None = None, - out: blosc2.Array | np.ndarray = None, + out: blosc2.Array = None, where: tuple | list | None = None, local_dict: dict | None = None, global_dict: dict | None = None, @@ -3631,9 +3631,9 @@ def evaluate( ex: str, local_dict: dict | None = None, global_dict: dict | None = None, - out: np.ndarray | blosc2.Array = None, + out: blosc2.Array = None, **kwargs: Any, -) -> np.ndarray | blosc2.Array: +) -> blosc2.Array: """ Evaluate a string expression using the Blosc2 compute engine. diff --git a/src/blosc2/linalg.py b/src/blosc2/linalg.py index d7f85d3b..1ea0617e 100644 --- a/src/blosc2/linalg.py +++ b/src/blosc2/linalg.py @@ -15,7 +15,7 @@ from collections.abc import Sequence -def matmul(x1: blosc2.NDArray | np.ndarray, x2: blosc2.NDArray, **kwargs: Any) -> blosc2.NDArray: +def matmul(x1: blosc2.Array, x2: blosc2.NDArray, **kwargs: Any) -> blosc2.NDArray: """ Computes the matrix product between two Blosc2 NDArrays. @@ -417,7 +417,7 @@ def vecdot(x1: blosc2.NDArray, x2: blosc2.NDArray, axis: int = -1, **kwargs) -> def permute_dims( - arr: blosc2.NDArray | np.ndarray, axes: tuple[int] | list[int] | None = None, **kwargs: Any + arr: blosc2.Array, axes: tuple[int] | list[int] | None = None, **kwargs: Any ) -> blosc2.NDArray: """ Permutes the axes (dimensions) of an array. @@ -566,7 +566,7 @@ def transpose(x, **kwargs: Any) -> blosc2.NDArray: return permute_dims(x, **kwargs) -def matrix_transpose(arr: blosc2.NDArray | np.ndarray, **kwargs: Any) -> blosc2.NDArray: +def matrix_transpose(arr: blosc2.Array, **kwargs: Any) -> blosc2.NDArray: """ Transposes a matrix (or a stack of matrices). diff --git a/src/blosc2/ndarray.py b/src/blosc2/ndarray.py index 3c0b378b..e8657371 100644 --- a/src/blosc2/ndarray.py +++ b/src/blosc2/ndarray.py @@ -420,7 +420,7 @@ def sum( dtype: np.dtype | str = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | blosc2.Array | int | float | complex | bool: +) -> blosc2.Array | int | float | complex | bool: """ Return the sum of array elements over a given axis. @@ -477,7 +477,7 @@ def mean( dtype: np.dtype | str = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | blosc2.Array | int | float | complex | bool: +) -> blosc2.Array | int | float | complex | bool: """ Return the arithmetic mean along the specified axis. @@ -514,7 +514,7 @@ def std( ddof: int = 0, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | blosc2.Array | int | float | bool: +) -> blosc2.Array | int | float | bool: """ Return the standard deviation along the specified axis. @@ -573,7 +573,7 @@ def var( ddof: int = 0, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | blosc2.Array | int | float | bool: +) -> blosc2.Array | int | float | bool: """ Return the variance along the specified axis. @@ -614,7 +614,7 @@ def prod( dtype: np.dtype | str = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | blosc2.Array | int | float | complex | bool: +) -> blosc2.Array | int | float | complex | bool: """ Return the product of array elements over a given axis. @@ -653,7 +653,7 @@ def min( axis: int | tuple[int] | None = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | blosc2.Array | int | float | complex | bool: +) -> blosc2.Array | int | float | complex | bool: """ Return the minimum along a given axis. @@ -701,7 +701,7 @@ def max( axis: int | tuple[int] | None = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | blosc2.Array | int | float | complex | bool: +) -> blosc2.Array | int | float | complex | bool: """ Return the maximum along a given axis. @@ -744,7 +744,7 @@ def any( axis: int | tuple[int] | None = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | blosc2.Array | bool: +) -> blosc2.Array | bool: """ Test whether any array element along a given axis evaluates to True. @@ -785,7 +785,7 @@ def all( axis: int | tuple[int] | None = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | blosc2.Array | bool: +) -> blosc2.Array | bool: """ Test whether all array elements along a given axis evaluate to True. @@ -4689,8 +4689,8 @@ def array_from_ffi_ptr(array_ptr) -> NDArray: def where( condition: blosc2.LazyExpr | NDArray, - x: NDArray | NDField | np.ndarray | int | float | complex | bool | str | bytes | None = None, - y: NDArray | NDField | np.ndarray | int | float | complex | bool | str | bytes | None = None, + x: blosc2.Array | int | float | complex | bool | str | bytes | None = None, + y: blosc2.Array | int | float | complex | bool | str | bytes | None = None, ) -> blosc2.LazyExpr: """ Return elements chosen from `x` or `y` depending on `condition`. @@ -5561,7 +5561,7 @@ def save(array: NDArray, urlpath: str, contiguous=True, **kwargs: Any) -> None: array.save(urlpath, contiguous, **kwargs) -def asarray(array: Sequence | np.ndarray | blosc2.Array, copy: bool | None = None, **kwargs: Any) -> NDArray: +def asarray(array: Sequence | blosc2.Array, copy: bool | None = None, **kwargs: Any) -> NDArray: """Convert the `array` to an `NDArray`. Parameters @@ -5664,7 +5664,7 @@ def asarray(array: Sequence | np.ndarray | blosc2.Array, copy: bool | None = Non def astype( - array: Sequence | np.ndarray | blosc2.Array, + array: Sequence | blosc2.Array, dtype, casting: str = "unsafe", copy: bool = True, @@ -5675,7 +5675,7 @@ def astype( Parameters ---------- - array: Sequence | np.ndarray | blosc2.Array + array: Sequence | blosc2.Array The array to be cast to a different type. dtype: DType-like The desired data type to cast to. @@ -5953,7 +5953,7 @@ def __getitem__(self, key: int | slice | Sequence[slice]) -> np.ndarray: # And return the field return nparr[self.field] - def __setitem__(self, key: int | slice | Sequence[slice], value: np.ndarray | NDArray | NDField) -> None: + def __setitem__(self, key: int | slice | Sequence[slice], value: blosc2.Array) -> None: """ Set a slice of :paramref:`self` to a value. @@ -6126,7 +6126,7 @@ def full_like(x: NDArray, fill_value: bool | int | float | complex, dtype=None, return blosc2.full(shape=x.shape, fill_value=fill_value, dtype=dtype, **kwargs) -def take(x: NDArray, indices: NDArray[int] | np.ndarray[int], axis: int | None = None) -> NDArray: +def take(x: NDArray, indices: blosc2.Array, axis: int | None = None) -> NDArray: """ Returns elements of an array along an axis. @@ -6165,7 +6165,7 @@ def take(x: NDArray, indices: NDArray[int] | np.ndarray[int], axis: int | None = return blosc2.asarray(x[key]) -def take_along_axis(x: NDArray, indices: NDArray[int] | np.ndarray[int], axis: int = -1) -> NDArray: +def take_along_axis(x: NDArray, indices: blosc2.Array, axis: int = -1) -> NDArray: """ Returns elements of an array along an axis. diff --git a/src/blosc2/tree_store.py b/src/blosc2/tree_store.py index ad4c0c6e..e6bf5fdb 100644 --- a/src/blosc2/tree_store.py +++ b/src/blosc2/tree_store.py @@ -8,15 +8,18 @@ import contextlib import os from collections.abc import Iterator, MutableMapping +from typing import TYPE_CHECKING import numpy as np import blosc2 -from blosc2.c2array import C2Array from blosc2.dict_store import DictStore -from blosc2.ndarray import NDArray from blosc2.schunk import SChunk +if TYPE_CHECKING: + from blosc2.c2array import C2Array + from blosc2.ndarray import NDArray + class vlmetaProxy(MutableMapping): """Proxy for SChunk.vlmeta to control access and slicing. @@ -223,7 +226,7 @@ def _validate_key(self, key: str) -> str: return key - def __setitem__(self, key: str, value: np.ndarray | NDArray | C2Array | SChunk) -> None: + def __setitem__(self, key: str, value: blosc2.Array | SChunk) -> None: """Add a node with hierarchical key validation. Parameters From f15a1964c30499a33220ef6a5d8f403fa695395b Mon Sep 17 00:00:00 2001 From: Francesc Alted Date: Sat, 27 Sep 2025 15:14:05 +0200 Subject: [PATCH 3/7] [WIP] NDArray -> blosc2.Array --- src/blosc2/lazyexpr.py | 6 +++--- src/blosc2/ndarray.py | 30 ++++++++++++++++-------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/blosc2/lazyexpr.py b/src/blosc2/lazyexpr.py index 379ee934..a4601e9c 100644 --- a/src/blosc2/lazyexpr.py +++ b/src/blosc2/lazyexpr.py @@ -2027,7 +2027,7 @@ def chunked_eval( # noqa: C901 _getitem: bool, optional Indicates whether the expression is being evaluated for a getitem operation. Default is False. - _output: NDArray or np.ndarray, optional + _output: blosc2.Array, optional The output array to store the result. _ne_args: dict, optional Additional arguments to be passed to `numexpr.evaluate()` function. @@ -3502,7 +3502,7 @@ def lazyexpr( The dictionary with operands. Supported values are NumPy.ndarray, Python scalars, :ref:`NDArray`, :ref:`NDField` or :ref:`C2Array` instances. If None, the operands will be seeked in the local and global dictionaries. - out: NDArray or np.ndarray, optional + out: blosc2.Array, optional The output array where the result will be stored. If not provided, a new NumPy array will be created and returned. where: tuple, list, optional @@ -3657,7 +3657,7 @@ def evaluate( global_dict: dict, optional The global dictionary to use when looking for operands in the expression. If not provided, the global dictionary of the caller will be used. - out: NDArray or np.ndarray, optional + out: blosc2.Array, optional The output array where the result will be stored. If not provided, a new NumPy array will be created and returned. kwargs: Any, optional diff --git a/src/blosc2/ndarray.py b/src/blosc2/ndarray.py index e8657371..8f272992 100644 --- a/src/blosc2/ndarray.py +++ b/src/blosc2/ndarray.py @@ -2848,21 +2848,23 @@ def remainder( def clip( - x: NDArray, min: int | float | NDArray | None = None, max: int | float | NDArray | None = None + x: blosc2.Array, + min: int | float | blosc2.Array | None = None, + max: int | float | blosc2.Array | None = None, ) -> NDArray: """ Clamps each element x_i of the input array x to the range [min, max]. Parameters ---------- - x: NDArray + x: blosc2.Array Input array. Should have a real-valued data type. - min: int | float | NDArray | None + min: int | float | blosc2.Array | None Lower-bound of the range to which to clamp. If None, no lower bound must be applied. Default: None. - max: int | float | NDArray | None + max: int | float | blosc2.Array | None Upper-bound of the range to which to clamp. If None, no upper bound must be applied. Default: None. @@ -2880,7 +2882,7 @@ def chunkwise_clip(inputs, output, offset): return blosc2.lazyudf(chunkwise_clip, (x, min, max), dtype=x.dtype, shape=x.shape) -def logaddexp(x1: int | float | NDArray, x2: int | float | NDArray) -> NDArray: +def logaddexp(x1: int | float | blosc2.Array, x2: int | float | blosc2.Array) -> NDArray: """ Calculates the logarithm of the sum of exponentiations log(exp(x1) + exp(x2)) for each element x1_i of the input array x1 with the respective element x2_i of the @@ -4647,7 +4649,7 @@ def __matmul__(self, other): return blosc2.linalg.matmul(self, other) -def squeeze(x: NDArray, axis: int | None = None) -> NDArray: +def squeeze(x: blosc2.Array, axis: int | None = None) -> NDArray: """ Remove single-dimensional entries from the shape of the array. @@ -6015,13 +6017,13 @@ def __setitem__(self, selection, input) -> np.ndarray: # return NotImplementedError -def empty_like(x: NDArray, dtype=None, **kwargs) -> NDArray: +def empty_like(x: blosc2.Array, dtype=None, **kwargs) -> NDArray: """ Returns an uninitialized array with the same shape as an input array x. Parameters ---------- - x : NDArray + x : blosc2.Array Input array from which to derive the output array shape. dtype (Optional): @@ -6042,13 +6044,13 @@ def empty_like(x: NDArray, dtype=None, **kwargs) -> NDArray: return blosc2.empty(shape=x.shape, dtype=dtype, **kwargs) -def ones_like(x: NDArray, dtype=None, **kwargs) -> NDArray: +def ones_like(x: blosc2.Array, dtype=None, **kwargs) -> NDArray: """ Returns an array of ones with the same shape as an input array x. Parameters ---------- - x : NDArray + x : blosc2.Array Input array from which to derive the output array shape. dtype (Optional): @@ -6069,13 +6071,13 @@ def ones_like(x: NDArray, dtype=None, **kwargs) -> NDArray: return blosc2.ones(shape=x.shape, dtype=dtype, **kwargs) -def zeros_like(x: NDArray, dtype=None, **kwargs) -> NDArray: +def zeros_like(x: blosc2.Array, dtype=None, **kwargs) -> NDArray: """ Returns an array of zeros with the same shape as an input array x. Parameters ---------- - x : NDArray + x : blosc2.Array Input array from which to derive the output array shape. dtype (Optional): @@ -6096,13 +6098,13 @@ def zeros_like(x: NDArray, dtype=None, **kwargs) -> NDArray: return blosc2.zeros(shape=x.shape, dtype=dtype, **kwargs) -def full_like(x: NDArray, fill_value: bool | int | float | complex, dtype=None, **kwargs) -> NDArray: +def full_like(x: blosc2.Array, fill_value: bool | int | float | complex, dtype=None, **kwargs) -> NDArray: """ Returns an array filled with a value with the same shape as an input array x. Parameters ---------- - x : NDArray + x : blosc2.Array Input array from which to derive the output array shape. fill_value: bool | int | float | complex From 5b40a24e920f689ee143efe86489fafa26460283 Mon Sep 17 00:00:00 2001 From: Francesc Alted Date: Mon, 29 Sep 2025 12:00:31 +0200 Subject: [PATCH 4/7] Some fixes for NDArray types --- src/blosc2/lazyexpr.py | 34 +++++++++++++++++----------------- src/blosc2/ndarray.py | 34 +++++++++++++++++----------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/blosc2/lazyexpr.py b/src/blosc2/lazyexpr.py index a4601e9c..fbcbb5b4 100644 --- a/src/blosc2/lazyexpr.py +++ b/src/blosc2/lazyexpr.py @@ -286,9 +286,9 @@ def sort(self, order: str | list[str] | None = None) -> blosc2.LazyArray: pass @abstractmethod - def compute(self, item: slice | list[slice] | None = None, **kwargs: Any) -> blosc2.Array: + def compute(self, item: slice | list[slice] | None = None, **kwargs: Any) -> blosc2.NDArray: """ - Return an :ref:`NDArray` containing the evaluation of the :ref:`LazyArray`. + Return a :ref:`NDArray` containing the evaluation of the :ref:`LazyArray`. Parameters ---------- @@ -392,7 +392,7 @@ def save(self, **kwargs: Any) -> None: Notes ----- - * All the operands of the LazyArray must be Python scalars, :ref:`NDArray`, :ref:`C2Array` or :ref:`Proxy`. + * All the operands of the LazyArray must be Python scalars, or :ref:`blosc2.Array` objects. * If an operand is a :ref:`Proxy`, keep in mind that Python-Blosc2 will only be able to reopen it as such if its source is a :ref:`SChunk`, :ref:`NDArray` or a :ref:`C2Array` (see :func:`blosc2.open` notes section for more info). @@ -3376,7 +3376,7 @@ def save(self, **kwargs): def lazyudf( func: Callable[[tuple, np.ndarray, tuple[int]], None], - inputs: tuple | list | None, + inputs: Sequence[Any] | None, dtype: np.dtype, shape: tuple | list | None = None, chunked_eval: bool = True, @@ -3394,11 +3394,11 @@ def lazyudf( in :paramref:`inputs`. - `output`: The buffer to be filled as a multidimensional numpy.ndarray. - `offset`: The multidimensional offset corresponding to the start of the block being computed. - inputs: tuple or list or None - The sequence of inputs. Supported inputs are: - NumPy.ndarray, :ref:`NDArray`, :ref:`NDField`, :ref:`C2Array`. - Any other object is supported too, and will be passed as is to the user-defined function. - If not needed, this can be empty, but `shape` must be provided. + inputs: Sequence[Any] or None + The sequence of inputs. Besides objects compliant with the blosc2.Array protocol, + any other object is supported too, and it will be passed as-is to the + user-defined function. If not needed, this can be empty, but `shape` must + be provided. dtype: np.dtype The resulting ndarray dtype in NumPy format. shape: tuple, optional @@ -3480,7 +3480,7 @@ def seek_operands(names, local_dict=None, global_dict=None, _frame_depth: int = def lazyexpr( - expression: str | bytes | LazyExpr | blosc2.NDArray, + expression: str | bytes | LazyArray | blosc2.NDArray, operands: dict | None = None, out: blosc2.Array = None, where: tuple | list | None = None, @@ -3494,13 +3494,13 @@ def lazyexpr( Parameters ---------- - expression: str or bytes or LazyExpr - The expression to evaluate. This can be any valid expression that can be - ingested by numexpr. If a LazyExpr is passed, the expression will be + expression: str or bytes or LazyExpr or NDArray + The expression to evaluate. This can be any valid expression that numexpr + can ingest. If a LazyExpr is passed, the expression will be updated with the new operands. - operands: dict - The dictionary with operands. Supported values are NumPy.ndarray, - Python scalars, :ref:`NDArray`, :ref:`NDField` or :ref:`C2Array` instances. + operands: dict[blosc2.Array], optional + The dictionary with operands. Supported values are Python scalars, + or any instance that is blosc2.Array compliant. If None, the operands will be seeked in the local and global dictionaries. out: blosc2.Array, optional The output array where the result will be stored. If not provided, @@ -3665,7 +3665,7 @@ def evaluate( Returns ------- - out: NumPy or NDArray + out: blosc2.Array The result of the expression evaluation. If out is provided, the result will be stored in out and returned at the same time. diff --git a/src/blosc2/ndarray.py b/src/blosc2/ndarray.py index 8f272992..17d7e8ec 100644 --- a/src/blosc2/ndarray.py +++ b/src/blosc2/ndarray.py @@ -4649,7 +4649,7 @@ def __matmul__(self, other): return blosc2.linalg.matmul(self, other) -def squeeze(x: blosc2.Array, axis: int | None = None) -> NDArray: +def squeeze(x: NDArray, axis: int | None = None) -> NDArray: """ Remove single-dimensional entries from the shape of the array. @@ -5572,7 +5572,7 @@ def asarray(array: Sequence | blosc2.Array, copy: bool | None = None, **kwargs: An array supporting numpy array interface. copy: bool | None, optional - Whether or not to copy the input. If True, the function copies. + Whether to copy the input. If True, the function copies. If False, raise a ValueError if copy is necessary. If None and input is NDArray, avoid copy by returning lazyexpr. Default: None. @@ -5793,7 +5793,7 @@ def get_slice_nchunks( return blosc2_ext.schunk_get_slice_nchunks(schunk, key) -def indices(array: NDArray, order: str | list[str] | None = None, **kwargs: Any) -> NDArray: +def indices(array: blosc2.Array, order: str | list[str] | None = None, **kwargs: Any) -> NDArray: """ Return the indices of a sorted array following the specified order. @@ -5801,7 +5801,7 @@ def indices(array: NDArray, order: str | list[str] | None = None, **kwargs: Any) Parameters ---------- - array: :ref:`NDArray` + array: :ref:`blosc2.Array` The (structured) array to be sorted. order: str, list of str, optional Specifies which fields to compare first, second, etc. A single @@ -5828,7 +5828,7 @@ def indices(array: NDArray, order: str | list[str] | None = None, **kwargs: Any) return larr.indices(order).compute(**kwargs) -def sort(array: NDArray, order: str | list[str] | None = None, **kwargs: Any) -> NDArray: +def sort(array: blosc2.Array, order: str | list[str] | None = None, **kwargs: Any) -> NDArray: """ Return a sorted array following the specified order. @@ -5836,7 +5836,7 @@ def sort(array: NDArray, order: str | list[str] | None = None, **kwargs: Any) -> Parameters ---------- - array: :ref:`NDArray` + array: :ref:`blosc2.Array` The (structured) array to be sorted. order: str, list of str, optional Specifies which fields to compare first, second, etc. A single @@ -5963,12 +5963,12 @@ def __setitem__(self, key: int | slice | Sequence[slice], value: blosc2.Array) - ---------- key: int or slice or Sequence[slice] The slice to be set. - value: np.ndarray or NDArray or NDField + value: blosc2.Array The value to be set. """ if isinstance(key, str): raise TypeError("This array is a NDField; use a structured NDArray for bool expressions") - if isinstance(value, (NDField, NDArray)): + if not isinstance(value, np.ndarray): value = value[:] # Get the values in the parent NDArray nparr = self.ndarr[key] @@ -6128,13 +6128,13 @@ def full_like(x: blosc2.Array, fill_value: bool | int | float | complex, dtype=N return blosc2.full(shape=x.shape, fill_value=fill_value, dtype=dtype, **kwargs) -def take(x: NDArray, indices: blosc2.Array, axis: int | None = None) -> NDArray: +def take(x: blosc2.Array, indices: blosc2.Array, axis: int | None = None) -> NDArray: """ Returns elements of an array along an axis. Parameters ---------- - x: NDArray + x: blosc2.Array Input array. Should have one or more dimensions (axes). indices: array-like @@ -6167,13 +6167,13 @@ def take(x: NDArray, indices: blosc2.Array, axis: int | None = None) -> NDArray: return blosc2.asarray(x[key]) -def take_along_axis(x: NDArray, indices: blosc2.Array, axis: int = -1) -> NDArray: +def take_along_axis(x: blosc2.Array, indices: blosc2.Array, axis: int = -1) -> NDArray: """ Returns elements of an array along an axis. Parameters ---------- - x: NDArray + x: blosc2.Array Input array. Should have one or more dimensions (axes). indices: array-like @@ -6319,14 +6319,14 @@ def get_intersecting_chunks(_slice, shape, chunks): ) # chunk is whole array so just return full tuple to do loop once -def broadcast_to(arr, shape): +def broadcast_to(arr: blosc2.Array, shape: tuple[int, ...]) -> NDArray: """ Broadcast an array to a new shape. Warning: Computes a lazyexpr, so probably a bit suboptimal Parameters ---------- - array: NDArray + arr: blosc2.Array The array to broadcast. shape: tuple @@ -6337,16 +6337,16 @@ def broadcast_to(arr, shape): broadcast: NDArray A new array with the given shape. """ - return (arr + blosc2.zeros(shape, dtype=arr.dtype)).compute() # return lazyexpr quickly + return (arr + blosc2.zeros(shape, dtype=arr.dtype)).compute() -def meshgrid(*arrays: NDArray, indexing: str = "xy") -> Sequence[NDArray]: +def meshgrid(*arrays: blosc2.Array, indexing: str = "xy") -> Sequence[NDArray]: """ Returns coordinate matrices from coordinate vectors. Parameters ---------- - arrays: NDArray + *arrays: blosc2.Array An arbitrary number of one-dimensional arrays representing grid coordinates. Each array should have the same numeric data type. indexing: str From e499e45b1382d2abd6aeb2bdf8747b0cabc749a4 Mon Sep 17 00:00:00 2001 From: Francesc Alted Date: Mon, 29 Sep 2025 14:03:21 +0200 Subject: [PATCH 5/7] Add new Array protocol to the docs --- doc/reference/array.rst | 23 +++++++++++++++++++++++ doc/reference/classes.rst | 10 ++++++---- src/blosc2/ndarray.py | 16 ++++++++++++++-- 3 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 doc/reference/array.rst diff --git a/doc/reference/array.rst b/doc/reference/array.rst new file mode 100644 index 00000000..6d114cb4 --- /dev/null +++ b/doc/reference/array.rst @@ -0,0 +1,23 @@ +.. _Array: + +Array +===== + +Minimal typing protocol for array-like objects compatible with blosc2. + +This protocol describes the basic interface required by blosc2 arrays. +It is implemented by blosc2 classes (:ref:`NDArray`, :ref:`NDField`, +:ref:`LazyArray`, :ref:`C2Array`, :ref:`ProxyNDSource`...) +and is compatible with NumPy arrays and other array-like containers +(e.g., PyTorch, TensorFlow, Dask, Zarr, ...). + +.. currentmodule:: blosc2 + +.. autoclass:: Array + + :Special Methods: + + .. autosummary:: + + __len__ + __getitem__ diff --git a/doc/reference/classes.rst b/doc/reference/classes.rst index 0b688a71..1d9de69f 100644 --- a/doc/reference/classes.rst +++ b/doc/reference/classes.rst @@ -7,11 +7,12 @@ Main Classes ------------ .. autosummary:: - SChunk NDArray NDField LazyArray C2Array + Array + SChunk DictStore TreeStore EmbedStore @@ -23,14 +24,15 @@ Main Classes .. toctree:: :maxdepth: 1 - schunk ndarray ndfield + lazyarray + c2array + array + schunk dict_store tree_store embed_store - lazyarray - c2array proxy proxysource proxyndsource diff --git a/src/blosc2/ndarray.py b/src/blosc2/ndarray.py index 17d7e8ec..eb1503b1 100644 --- a/src/blosc2/ndarray.py +++ b/src/blosc2/ndarray.py @@ -43,8 +43,11 @@ class Array(Protocol): """ A typing protocol for array-like objects with basic array interface. - This protocol defines the minimal interface that array-like objects - must implement to be compatible with blosc2 functions. + This protocol describes the basic interface required by blosc2 arrays. + It is implemented by blosc2 classes (:ref:`NDArray`, :ref:`NDField`, + :ref:`LazyArray`, :ref:`C2Array`, :ref:`ProxyNDSource`...) + and is compatible with NumPy arrays and other array-like containers + (e.g., PyTorch, TensorFlow, Dask, Zarr, ...). """ @property @@ -57,6 +60,15 @@ def shape(self) -> tuple[int, ...]: """The shape of the array.""" ... + @property + def ndim(self) -> int: + """The number of dimensions of the array.""" + ... + + def __len__(self) -> int: + """The length of the array.""" + ... + def __getitem__(self, key: Any) -> Any: """Get items from the array.""" ... From 40e568c194b8c082f3331f077fca622c2892895e Mon Sep 17 00:00:00 2001 From: Francesc Alted Date: Mon, 29 Sep 2025 14:27:59 +0200 Subject: [PATCH 6/7] Fix checks for allowed dtypes --- src/blosc2/ndarray.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/blosc2/ndarray.py b/src/blosc2/ndarray.py index eb1503b1..1821d215 100644 --- a/src/blosc2/ndarray.py +++ b/src/blosc2/ndarray.py @@ -408,21 +408,20 @@ def reshape( def _check_allowed_dtypes( value: bool | int | float | str | blosc2.Array | blosc2.Proxy | blosc2.LazyExpr, ): - if not ( - isinstance( - value, - blosc2.LazyExpr - | blosc2.Array - | blosc2.Proxy - | blosc2.ProxyNDField - | blosc2.SimpleProxy - | np.ndarray, - ) - or np.isscalar(value) - ): + def _is_array_like(v: Any) -> bool: + try: + # Try Protocol runtime check first (works when possible) + if isinstance(v, blosc2.Array): + return True + except Exception: + # Some runtime contexts may raise (or return False) — fall back to duck typing + pass + # Structural fallback: common minimal array interface + return hasattr(v, "shape") and hasattr(v, "dtype") and callable(getattr(v, "__getitem__", None)) + + if not (_is_array_like(value) or np.isscalar(value)): raise RuntimeError( - "Expected LazyExpr, Array, Proxy, np.ndarray or scalar instances" - f" and you provided a '{type(value)}' instance" + f"Expected blosc2.Array or scalar instances and you provided a '{type(value)}' instance" ) From b4210750fef621c45959e3ccfd80e5280cee5a24 Mon Sep 17 00:00:00 2001 From: Francesc Alted Date: Mon, 29 Sep 2025 17:30:28 +0200 Subject: [PATCH 7/7] Suggestions by Luke --- src/blosc2/lazyexpr.py | 14 +++++++------- src/blosc2/ndarray.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/blosc2/lazyexpr.py b/src/blosc2/lazyexpr.py index fbcbb5b4..7bd85f54 100644 --- a/src/blosc2/lazyexpr.py +++ b/src/blosc2/lazyexpr.py @@ -337,9 +337,9 @@ def compute(self, item: slice | list[slice] | None = None, **kwargs: Any) -> blo pass @abstractmethod - def __getitem__(self, item: int | slice | Sequence[slice]) -> blosc2.Array: + def __getitem__(self, item: int | slice | Sequence[slice]) -> np.ndarray: """ - Return a NumPy.ndarray containing the evaluation of the :ref:`LazyArray`. + Return a numpy.ndarray containing the evaluation of the :ref:`LazyArray`. Parameters ---------- @@ -1152,7 +1152,7 @@ def fast_eval( # noqa: C901 operands: dict, getitem: bool, **kwargs, -) -> blosc2.Array: +) -> blosc2.NDArray | np.ndarray: """Evaluate the expression in chunks of operands using a fast path. Parameters @@ -1319,7 +1319,7 @@ def slices_eval( # noqa: C901 getitem: bool, _slice=NDINDEX_EMPTY_TUPLE, **kwargs, -) -> blosc2.Array: +) -> blosc2.NDArray | np.ndarray: """Evaluate the expression in chunks of operands. This function can handle operands with different chunk shapes and @@ -1722,7 +1722,7 @@ def reduce_slices( # noqa: C901 reduce_args, _slice=NDINDEX_EMPTY_TUPLE, **kwargs, -) -> blosc2.Array: +) -> blosc2.NDArray | np.ndarray: """Evaluate the expression in chunks of operands. This function can handle operands with different chunk shapes. @@ -2967,7 +2967,7 @@ def sort(self, order: str | list[str] | None = None) -> blosc2.LazyArray: lazy_expr._order = order return lazy_expr - def compute(self, item=(), **kwargs) -> blosc2.Array: + def compute(self, item=(), **kwargs) -> blosc2.NDArray: # When NumPy ufuncs are called, the user may add an `out` parameter to kwargs if "out" in kwargs: kwargs["_output"] = kwargs.pop("out") @@ -3250,7 +3250,7 @@ def info(self): def info_items(self): inputs = {} for key, value in self.inputs_dict.items(): - if isinstance(value, blosc2.Array | blosc2.C2Array): + if isinstance(value, blosc2.Array): inputs[key] = f"<{value.__class__.__name__}> {value.shape} {value.dtype}" else: inputs[key] = str(value) diff --git a/src/blosc2/ndarray.py b/src/blosc2/ndarray.py index 1821d215..113c7f86 100644 --- a/src/blosc2/ndarray.py +++ b/src/blosc2/ndarray.py @@ -406,7 +406,7 @@ def reshape( def _check_allowed_dtypes( - value: bool | int | float | str | blosc2.Array | blosc2.Proxy | blosc2.LazyExpr, + value: bool | int | float | str | blosc2.Array, ): def _is_array_like(v: Any) -> bool: try: