diff --git a/numba_typing/new_types/__init__.py b/numba_typing/new_types/__init__.py new file mode 100644 index 000000000..240ba8240 --- /dev/null +++ b/numba_typing/new_types/__init__.py @@ -0,0 +1,2 @@ + +__all__ = ['array', 'number_types', 'pandas_series', 'special_LiteralType'] diff --git a/numba_typing/new_types/array.py b/numba_typing/new_types/array.py new file mode 100644 index 000000000..ea1595dc8 --- /dev/null +++ b/numba_typing/new_types/array.py @@ -0,0 +1,17 @@ +import typing +import numpy as np +from abc import abstractmethod + +T = typing.TypeVar('T') +S = typing.TypeVar('S') + + +class Array(typing.Generic[T, S]): + '''Annotation for np.ndarray + Use square brackets to indicate type and dimension + For example: Array[int, typing_extensions.Literal[4]]''' + __slots__ = () + + @abstractmethod + def __array__(self) -> np.ndarray: + pass diff --git a/numba_typing/new_types/number_types.py b/numba_typing/new_types/number_types.py new file mode 100644 index 000000000..e279dca2c --- /dev/null +++ b/numba_typing/new_types/number_types.py @@ -0,0 +1,80 @@ +import typing +from abc import abstractmethod +import typing_extensions + + +class int8(typing_extensions.Protocol): + """Annotation for int8""" + @abstractmethod + def __int__(self) -> int: + pass + + +class int16(typing_extensions.Protocol): + """Annotation for int16""" + @abstractmethod + def __int__(self) -> int: + pass + + +class int32(typing_extensions.Protocol): + """Annotation for int32""" + @abstractmethod + def __int__(self) -> int: + pass + + +class int64(typing_extensions.Protocol): + """Annotation for int64""" + @abstractmethod + def __int__(self) -> int: + pass + + +class unint8(typing_extensions.Protocol): + """Annotation for unsigned int8""" + @abstractmethod + def __int__(self) -> int: + pass + + +class unint16(typing_extensions.Protocol): + """Annotation for unsigned int16""" + @abstractmethod + def __int__(self) -> int: + pass + + +class unint32(typing_extensions.Protocol): + """Annotation for unsigned int32""" + @abstractmethod + def __int__(self) -> int: + pass + + +class unint64(typing_extensions.Protocol): + """Annotation for unsigned int64""" + @abstractmethod + def __int__(self) -> int: + pass + + +class float32(typing_extensions.Protocol): + """Annotation for float32""" + @abstractmethod + def __float__(self) -> float: + pass + + +class float64(typing_extensions.Protocol): + """Annotation for float32""" + @abstractmethod + def __float__(self) -> float: + pass + + +number = typing.Union[int, float] # numba's number type + + +T_int = typing.TypeVar('T_int', int8, int16, int32, int64) +T_float = typing.TypeVar('T_float', float32, float64) diff --git a/numba_typing/new_types/pandas_Series.py b/numba_typing/new_types/pandas_Series.py new file mode 100644 index 000000000..f98eea48f --- /dev/null +++ b/numba_typing/new_types/pandas_Series.py @@ -0,0 +1,18 @@ +import typing +import pandas as pd +from abc import abstractmethod + +T = typing.TypeVar('T') +S = typing.TypeVar('S') + + +class Series(typing.Generic[T, S]): + '''Annotation for pandas.Series + For expample: Series[int, str] + int - type of index + str - type of value''' + __slots__ = () + + @abstractmethod + def __array__(self) -> pd.core.series.Series: + pass diff --git a/numba_typing/new_types/special.py b/numba_typing/new_types/special.py new file mode 100644 index 000000000..e2cc044f6 --- /dev/null +++ b/numba_typing/new_types/special.py @@ -0,0 +1,23 @@ +import typing +import number_types + +T = typing.TypeVar('T') + + +class LiteralType(typing.Generic[T]): + pass + + +class PreferLiteralType(typing.Generic[T]): + pass + + +class PreferNonLiteralType(typing.Generic[T]): + pass + + +L_int = LiteralType[int] +L_float = LiteralType[float] + +TL_int = LiteralType[number_types.T_int] +TL_float = LiteralType[number_types.T_float] diff --git a/numba_typing/new_types/special_LiteralType.py b/numba_typing/new_types/special_LiteralType.py new file mode 100644 index 000000000..e2cc044f6 --- /dev/null +++ b/numba_typing/new_types/special_LiteralType.py @@ -0,0 +1,23 @@ +import typing +import number_types + +T = typing.TypeVar('T') + + +class LiteralType(typing.Generic[T]): + pass + + +class PreferLiteralType(typing.Generic[T]): + pass + + +class PreferNonLiteralType(typing.Generic[T]): + pass + + +L_int = LiteralType[int] +L_float = LiteralType[float] + +TL_int = LiteralType[number_types.T_int] +TL_float = LiteralType[number_types.T_float] diff --git a/numba_typing/new_typing.py b/numba_typing/new_typing.py new file mode 100644 index 000000000..9f39aab27 --- /dev/null +++ b/numba_typing/new_typing.py @@ -0,0 +1,127 @@ +import typing +import numpy as np +import pandas as pd +from abc import abstractmethod +import typing_extensions + +T = typing.TypeVar('T') +S = typing.TypeVar('S') + + +class Array(typing.Generic[T, S]): + '''Annotation for np.ndarray + Use square brackets to indicate type and dimension + For example: Array[int, typing_extensions.Literal[4]]''' + __slots__ = () + + @abstractmethod + def __array__(self) -> np.ndarray: + pass + + +class Series(typing.Generic[T, S]): + '''Annotation for pandas.Series + For expample: Series[int, str] + int - type of index + str - type of value''' + __slots__ = () + + @abstractmethod + def __array__(self) -> pd.core.series.Series: + pass + + +class int8(typing_extensions.Protocol): + """Annotation for int8""" + @abstractmethod + def __int__(self) -> int: + pass + + +class int16(typing_extensions.Protocol): + """Annotation for int16""" + @abstractmethod + def __int__(self) -> int: + pass + + +class int32(typing_extensions.Protocol): + """Annotation for int32""" + @abstractmethod + def __int__(self) -> int: + pass + + +class int64(typing_extensions.Protocol): + """Annotation for int64""" + @abstractmethod + def __int__(self) -> int: + pass + + +class unint8(typing_extensions.Protocol): + """Annotation for unsigned int8""" + @abstractmethod + def __int__(self) -> int: + pass + + +class unint16(typing_extensions.Protocol): + """Annotation for unsigned int16""" + @abstractmethod + def __int__(self) -> int: + pass + + +class unint32(typing_extensions.Protocol): + """Annotation for unsigned int32""" + @abstractmethod + def __int__(self) -> int: + pass + + +class unint64(typing_extensions.Protocol): + """Annotation for unsigned int64""" + @abstractmethod + def __int__(self) -> int: + pass + + +class float32(typing_extensions.Protocol): + """Annotation for float32""" + @abstractmethod + def __float__(self) -> float: + pass + + +class float64(typing_extensions.Protocol): + """Annotation for float32""" + @abstractmethod + def __float__(self) -> float: + pass + + +number = typing.Union[int, float] # numba's number type + + +T_int = typing.TypeVar('T_int', int8, int16, int32, int64) +T_float = typing.TypeVar('T_float', float32, float64) + + +class LiteralType(typing.Generic[T]): + pass + + +class PreferLiteralType(typing.Generic[T]): + pass + + +class PreferNonLiteralType(typing.Generic[T]): + pass + + +L_int = LiteralType[int] +L_float = LiteralType[float] + +TL_int = LiteralType[T_int] +TL_float = LiteralType[T_float]