|
74 | 74 | npt: Any = None
|
75 | 75 |
|
76 | 76 |
|
| 77 | +# Functions that take Dict/Mapping/List/Sequence/Callable can be tricky to type: |
| 78 | +# - keys of Dict and Mapping do not accept sub-classes |
| 79 | +# - items of List and Sequence do not accept sub-classes |
| 80 | +# - input argument to Callable cannot be sub-classes |
| 81 | +# If you want to allow any type and it's sub-classes in the above cases, you can |
| 82 | +# use TypeVar("AllowsSubclasses", bound=class) |
| 83 | +HashableT = TypeVar("HashableT", bound=Hashable) |
| 84 | + |
77 | 85 | # array-like
|
78 | 86 |
|
79 | 87 | ArrayLike = Union["ExtensionArray", np.ndarray]
|
|
105 | 113 | NDFrameT = TypeVar("NDFrameT", bound="NDFrame")
|
106 | 114 |
|
107 | 115 | Axis = Union[str, int]
|
108 |
| -IndexLabel = Union[Hashable, Sequence[Hashable]] |
| 116 | +IndexLabel = Union[Hashable, Sequence[HashableT]] |
109 | 117 | Level = Union[Hashable, int]
|
110 | 118 | Shape = Tuple[int, ...]
|
111 | 119 | Suffixes = Tuple[Optional[str], Optional[str]]
|
|
127 | 135 | Dtype = Union["ExtensionDtype", NpDtype]
|
128 | 136 | AstypeArg = Union["ExtensionDtype", "npt.DTypeLike"]
|
129 | 137 | # DtypeArg specifies all allowable dtypes in a functions its dtype argument
|
130 |
| -DtypeArg = Union[Dtype, Dict[Hashable, Dtype]] |
| 138 | +DtypeArg = Union[Dtype, Dict[HashableT, Dtype]] |
131 | 139 | DtypeObj = Union[np.dtype, "ExtensionDtype"]
|
132 | 140 |
|
133 | 141 | # converters
|
134 |
| -ConvertersArg = Dict[Hashable, Callable[[Dtype], Dtype]] |
| 142 | +ConvertersArg = Dict[HashableT, Callable[[Dtype], Dtype]] |
135 | 143 |
|
136 | 144 | # parse_dates
|
137 | 145 | ParseDatesArg = Union[
|
138 |
| - bool, List[Hashable], List[List[Hashable]], Dict[Hashable, List[Hashable]] |
| 146 | + bool, List[HashableT], List[List[HashableT]], Dict[HashableT, List[Hashable]] |
139 | 147 | ]
|
140 | 148 |
|
141 | 149 | # For functions like rename that convert one label to another
|
142 |
| -Renamer = Union[Mapping[Hashable, Any], Callable[[Hashable], Hashable]] |
| 150 | +Renamer = Union[Mapping[HashableT, Any], Callable[[HashableT], Hashable]] |
143 | 151 |
|
144 | 152 | # to maintain type information across generic functions and parametrization
|
145 | 153 | T = TypeVar("T")
|
|
156 | 164 |
|
157 | 165 | # types of `func` kwarg for DataFrame.aggregate and Series.aggregate
|
158 | 166 | AggFuncTypeBase = Union[Callable, str]
|
159 |
| -AggFuncTypeDict = Dict[Hashable, Union[AggFuncTypeBase, List[AggFuncTypeBase]]] |
| 167 | +AggFuncTypeDict = Dict[HashableT, Union[AggFuncTypeBase, List[AggFuncTypeBase]]] |
160 | 168 | AggFuncType = Union[
|
161 | 169 | AggFuncTypeBase,
|
162 | 170 | List[AggFuncTypeBase],
|
@@ -260,10 +268,10 @@ def closed(self) -> bool:
|
260 | 268 | FormattersType = Union[
|
261 | 269 | List[Callable], Tuple[Callable, ...], Mapping[Union[str, int], Callable]
|
262 | 270 | ]
|
263 |
| -ColspaceType = Mapping[Hashable, Union[str, int]] |
| 271 | +ColspaceType = Mapping[HashableT, Union[str, int]] |
264 | 272 | FloatFormatType = Union[str, Callable, "EngFormatter"]
|
265 | 273 | ColspaceArgType = Union[
|
266 |
| - str, int, Sequence[Union[str, int]], Mapping[Hashable, Union[str, int]] |
| 274 | + str, int, Sequence[Union[str, int]], Mapping[HashableT, Union[str, int]] |
267 | 275 | ]
|
268 | 276 |
|
269 | 277 | # Arguments for fillna()
|
|
0 commit comments