2323from enum import Enum
2424from pathlib import Path
2525from queue import Empty , Queue
26- from typing import TYPE_CHECKING
26+ from typing import TYPE_CHECKING , Any
2727
2828from numpy .exceptions import ComplexWarning
2929
@@ -197,7 +197,7 @@ def sort(self, order: str | list[str] | None = None) -> blosc2.LazyArray:
197197 pass
198198
199199 @abstractmethod
200- def compute (self , item : slice | list [slice ] | None = None , ** kwargs : dict ) -> blosc2 .NDArray :
200+ def compute (self , item : slice | list [slice ] | None = None , ** kwargs : Any ) -> blosc2 .NDArray :
201201 """
202202 Return an :ref:`NDArray` containing the evaluation of the :ref:`LazyArray`.
203203
@@ -207,7 +207,7 @@ def compute(self, item: slice | list[slice] | None = None, **kwargs: dict) -> bl
207207 If not None, only the chunks that intersect with the slices
208208 in items will be evaluated.
209209
210- kwargs: dict , optional
210+ kwargs: Any , optional
211211 Keyword arguments that are supported by the :func:`empty` constructor.
212212 These arguments will be set in the resulting :ref:`NDArray`.
213213
@@ -284,13 +284,13 @@ def __getitem__(self, item: int | slice | Sequence[slice]) -> blosc2.NDArray:
284284 pass
285285
286286 @abstractmethod
287- def save (self , ** kwargs : dict ) -> None :
287+ def save (self , ** kwargs : Any ) -> None :
288288 """
289289 Save the :ref:`LazyArray` on disk.
290290
291291 Parameters
292292 ----------
293- kwargs: dict , optional
293+ kwargs: Any , optional
294294 Keyword arguments that are supported by the :func:`empty` constructor.
295295 The `urlpath` must always be provided.
296296
@@ -384,7 +384,7 @@ def info(self) -> InfoReporter:
384384
385385
386386def convert_inputs (inputs ):
387- if len (inputs ) == 0 :
387+ if not inputs or len (inputs ) == 0 :
388388 return []
389389 inputs_ = []
390390 for obj in inputs :
@@ -595,7 +595,10 @@ def validate_inputs(inputs: dict, out=None) -> tuple: # noqa: C901
595595 "You really want to pass at least one input or one output for building a LazyArray."
596596 " Maybe you want blosc2.empty() instead?"
597597 )
598- return out .shape , out .chunks , out .blocks , True
598+ if isinstance (out , blosc2 .NDArray ):
599+ return out .shape , out .chunks , out .blocks , True
600+ else :
601+ return out .shape , None , None , True
599602
600603 inputs = [input for input in inputs .values () if hasattr (input , "shape" ) and input is not np ]
601604 shape = compute_broadcast_shape (inputs )
@@ -878,7 +881,7 @@ def fast_eval( # noqa: C901
878881 getitem: bool, optional
879882 Indicates whether the expression is being evaluated for a getitem operation or eval().
880883 Default is False.
881- kwargs: dict , optional
884+ kwargs: Any , optional
882885 Additional keyword arguments supported by the :func:`empty` constructor.
883886
884887 Returns
@@ -892,6 +895,9 @@ def fast_eval( # noqa: C901
892895 if isinstance (out , blosc2 .NDArray ):
893896 # If 'out' has been passed, and is a NDArray, use it as the base array
894897 basearr = out
898+ elif isinstance (out , np .ndarray ):
899+ # If 'out' is a NumPy array, create a NDArray with the same shape and dtype
900+ basearr = blosc2 .empty (out .shape , dtype = out .dtype , ** kwargs )
895901 else :
896902 # Otherwise, find the operand with the 'chunks' attribute and the longest shape
897903 operands_with_chunks = [o for o in operands .values () if hasattr (o , "chunks" )]
@@ -1044,7 +1050,7 @@ def slices_eval( # noqa: C901
10441050 _slice: slice, list of slices, optional
10451051 If provided, only the chunks that intersect with this slice
10461052 will be evaluated.
1047- kwargs: dict , optional
1053+ kwargs: Any , optional
10481054 Additional keyword arguments that are supported by the :func:`empty` constructor.
10491055
10501056 Returns
@@ -1293,7 +1299,7 @@ def reduce_slices( # noqa: C901
12931299 _slice: slice, list of slices, optional
12941300 If provided, only the chunks that intersect with this slice
12951301 will be evaluated.
1296- kwargs: dict , optional
1302+ kwargs: Any , optional
12971303 Additional keyword arguments supported by the :func:`empty` constructor.
12981304
12991305 Returns
@@ -1530,7 +1536,7 @@ def chunked_eval( # noqa: C901
15301536 A dictionary containing the operands for the expression.
15311537 item: int, slice or sequence of slices, optional
15321538 The slice(s) to be retrieved. Note that step parameter is not honored yet.
1533- kwargs: dict , optional
1539+ kwargs: Any , optional
15341540 Additional keyword arguments supported by the :func:`empty` constructor. In addition,
15351541 the following keyword arguments are supported:
15361542 _getitem: bool, optional
@@ -2680,11 +2686,11 @@ def save(self, **kwargs):
26802686
26812687def lazyudf (
26822688 func : Callable [[tuple , np .ndarray , tuple [int ]], None ],
2683- inputs : tuple | list ,
2689+ inputs : tuple | list | None ,
26842690 dtype : np .dtype ,
2685- shape : tuple [ int ] | None = None ,
2691+ shape : tuple | list | None = None ,
26862692 chunked_eval : bool = True ,
2687- ** kwargs : dict ,
2693+ ** kwargs : Any ,
26882694) -> LazyUDF :
26892695 """
26902696 Get a LazyUDF from a python user-defined function.
@@ -2698,7 +2704,7 @@ def lazyudf(
26982704 in :paramref:`inputs`.
26992705 - `output`: The buffer to be filled as a multidimensional numpy.ndarray.
27002706 - `offset`: The multidimensional offset corresponding to the start of the block being computed.
2701- inputs: tuple or list
2707+ inputs: tuple or list or None
27022708 The sequence of inputs. Supported inputs are:
27032709 NumPy.ndarray, :ref:`NDArray`, :ref:`NDField`, :ref:`C2Array`.
27042710 Any other object is supported too, and will be passed as is to the user-defined function.
@@ -2709,7 +2715,7 @@ def lazyudf(
27092715 The shape of the resulting array. If None, the shape will be guessed from inputs.
27102716 chunked_eval: bool, optional
27112717 Whether to evaluate the function in chunks or not (blocks).
2712- kwargs: dict , optional
2718+ kwargs: Any , optional
27132719 Keyword arguments that are supported by the :func:`empty` constructor.
27142720 These arguments will be used by the :meth:`LazyArray.__getitem__` and
27152721 :meth:`LazyArray.eval` methods. The
0 commit comments