25
25
Type ,
26
26
Union ,
27
27
cast ,
28
+ overload ,
28
29
)
29
30
import warnings
30
31
107
108
)
108
109
109
110
if TYPE_CHECKING :
111
+ from typing import Literal
112
+
110
113
from pandas import Series
111
114
from pandas .core .arrays import (
112
115
DatetimeArray ,
@@ -1164,6 +1167,20 @@ def astype_td64_unit_conversion(
1164
1167
return result
1165
1168
1166
1169
1170
+ @overload
1171
+ def astype_nansafe (
1172
+ arr : np .ndarray , dtype : np .dtype , copy : bool = ..., skipna : bool = ...
1173
+ ) -> np .ndarray :
1174
+ ...
1175
+
1176
+
1177
+ @overload
1178
+ def astype_nansafe (
1179
+ arr : np .ndarray , dtype : ExtensionDtype , copy : bool = ..., skipna : bool = ...
1180
+ ) -> ExtensionArray :
1181
+ ...
1182
+
1183
+
1167
1184
def astype_nansafe (
1168
1185
arr : np .ndarray , dtype : DtypeObj , copy : bool = True , skipna : bool = False
1169
1186
) -> ArrayLike :
@@ -1190,14 +1207,10 @@ def astype_nansafe(
1190
1207
flags = arr .flags
1191
1208
flat = arr .ravel ("K" )
1192
1209
result = astype_nansafe (flat , dtype , copy = copy , skipna = skipna )
1193
- order = "F" if flags .f_contiguous else "C"
1210
+ order : Literal [ "C" , "F" ] = "F" if flags .f_contiguous else "C"
1194
1211
# error: Item "ExtensionArray" of "Union[ExtensionArray, ndarray]" has no
1195
1212
# attribute "reshape"
1196
- # error: No overload variant of "reshape" of "_ArrayOrScalarCommon" matches
1197
- # argument types "Tuple[int, ...]", "str"
1198
- return result .reshape ( # type: ignore[union-attr,call-overload]
1199
- arr .shape , order = order
1200
- )
1213
+ return result .reshape (arr .shape , order = order ) # type: ignore[union-attr]
1201
1214
1202
1215
# We get here with 0-dim from sparse
1203
1216
arr = np .atleast_1d (arr )
0 commit comments