Skip to content

Commit

Permalink
Add type annotations to lazyexpr.py
Browse files Browse the repository at this point in the history
  • Loading branch information
martaiborra committed Sep 13, 2024
1 parent dc410f9 commit dbeb43a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions src/blosc2/lazyexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import pathlib
import threading
from abc import ABC, abstractmethod
from collections.abc import Callable
from collections.abc import Callable, Sequence
from enum import Enum
from pathlib import Path
from queue import Empty, Queue
Expand Down Expand Up @@ -61,7 +61,7 @@ class LazyArrayEnum(Enum):

class LazyArray(ABC):
@abstractmethod
def eval(self, item, **kwargs):
def eval(self, item: slice | list[slice] = None, **kwargs: dict) -> blosc2.NDArray:
"""
Return a :ref:`NDArray` containing the evaluation of the :ref:`LazyArray`.
Expand Down Expand Up @@ -90,7 +90,7 @@ def eval(self, item, **kwargs):
pass

@abstractmethod
def __getitem__(self, item):
def __getitem__(self, item: int | slice | Sequence[slice]) -> blosc2.NDArray:
"""
Return a NumPy.ndarray containing the evaluation of the :ref:`LazyArray`.
Expand All @@ -107,7 +107,7 @@ def __getitem__(self, item):
pass

@abstractmethod
def save(self, **kwargs):
def save(self, **kwargs: dict) -> None:
"""
Save the :ref:`LazyArray` on disk.
Expand All @@ -133,7 +133,7 @@ def save(self, **kwargs):

@property
@abstractmethod
def dtype(self):
def dtype(self) -> np.dtype:
"""
Get the data type of the :ref:`LazyArray`.
Expand All @@ -146,7 +146,7 @@ def dtype(self):

@property
@abstractmethod
def shape(self):
def shape(self) -> tuple[int]:
"""
Get the shape of the :ref:`LazyArray`.
Expand All @@ -159,7 +159,7 @@ def shape(self):

@property
@abstractmethod
def info(self):
def info(self) -> InfoReporter:
"""
Get information about the :ref:`LazyArray`.
Expand Down Expand Up @@ -1873,7 +1873,8 @@ def _open_lazyarray(array):
return expr


def lazyudf(func, inputs, dtype, chunked_eval=True, **kwargs):
def lazyudf(func: Callable[[tuple, np.ndarray, tuple[int]], None], inputs: tuple | list,
dtype: np.dtype, chunked_eval: bool = True, **kwargs: dict) -> LazyUDF:
"""
Get a LazyUDF from a python user-defined function.
Expand Down Expand Up @@ -1908,7 +1909,8 @@ def lazyudf(func, inputs, dtype, chunked_eval=True, **kwargs):
return LazyUDF(func, inputs, dtype, chunked_eval, **kwargs)


def lazyexpr(expression, operands=None, out=None, where=None):
def lazyexpr(expression: str | bytes | LazyExpr, operands: dict = None,
out: blosc2.NDArray | np.ndarray = None, where: tuple | list = None) -> LazyExpr:
"""
Get a LazyExpr from an expression.
Expand Down
2 changes: 1 addition & 1 deletion src/blosc2/ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ def keep_last_read(self, value: bool) -> None:
self._keep_last_read = value

@property
def info(self):
def info(self) -> InfoReporter:
"""
Print information about this array.
Expand Down

0 comments on commit dbeb43a

Please sign in to comment.