Skip to content

Commit db3f82a

Browse files
committed
_numtype.StringArray* aliases for StringDType arrays
1 parent 46a32d2 commit db3f82a

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

src/_numtype/__init__.pyi

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import decimal
66
import fractions
77
from collections.abc import Sequence
88
from typing import Any, TypeAlias, type_check_only
9-
from typing_extensions import Protocol, TypeAliasType, TypeVar, Unpack
9+
from typing_extensions import Never, Protocol, TypeAliasType, TypeVar, Unpack
1010

1111
import numpy as np
1212
from numpy._typing import _NestedSequence
@@ -97,17 +97,14 @@ from ._scalar_co import (
9797
# Type parameters
9898

9999
_T = TypeVar("_T")
100+
_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...], default=tuple[int, ...])
100101
_ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True)
101102
_ScalarT = TypeVar("_ScalarT", bound=np.generic)
102103
_ScalarT_co = TypeVar("_ScalarT_co", bound=np.generic, covariant=True)
103104
_ScalarT0 = TypeVar("_ScalarT0", bound=np.generic, default=Any)
105+
_NaObjectT = TypeVar("_NaObjectT", default=Never)
104106
_ToT = TypeVar("_ToT")
105107

106-
###
107-
# Type constraints (bijective type mappings)
108-
109-
_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...], default=tuple[int, ...])
110-
111108
###
112109
# Protocols
113110

@@ -185,6 +182,37 @@ MArray3D = TypeAliasType("MArray3D", np.ma.MaskedArray[tuple[int, int, int], np.
185182

186183
Matrix = TypeAliasType("Matrix", np.matrix[tuple[int, int], np.dtype[_ScalarT0]], type_params=(_ScalarT0,))
187184

185+
StringArray = TypeAliasType(
186+
"StringArray",
187+
np.ndarray[_ShapeT, np.dtypes.StringDType[_NaObjectT]],
188+
type_params=(_ShapeT, _NaObjectT),
189+
)
190+
StringArray0D = TypeAliasType(
191+
"StringArray0D",
192+
np.ndarray[tuple[()], np.dtypes.StringDType[_NaObjectT]],
193+
type_params=(_NaObjectT,),
194+
)
195+
StringArray1D = TypeAliasType(
196+
"StringArray1D",
197+
np.ndarray[tuple[int], np.dtypes.StringDType[_NaObjectT]],
198+
type_params=(_NaObjectT,),
199+
)
200+
StringArray2D = TypeAliasType(
201+
"StringArray2D",
202+
np.ndarray[tuple[int, int], np.dtypes.StringDType[_NaObjectT]],
203+
type_params=(_NaObjectT,),
204+
)
205+
StringArray3D = TypeAliasType(
206+
"StringArray3D",
207+
np.ndarray[tuple[int, int, int], np.dtypes.StringDType[_NaObjectT]],
208+
type_params=(_NaObjectT,),
209+
)
210+
StringArrayND = TypeAliasType(
211+
"StringArrayND",
212+
np.ndarray[tuple[int, ...], np.dtypes.StringDType[_NaObjectT]],
213+
type_params=(_NaObjectT,),
214+
)
215+
188216
###
189217
# helper aliases
190218

0 commit comments

Comments
 (0)