2525 Type ,
2626 Union ,
2727 cast ,
28+ overload ,
2829)
2930import warnings
3031
107108)
108109
109110if TYPE_CHECKING :
111+ from typing import Literal
112+
110113 from pandas import Series
111114 from pandas .core .arrays import (
112115 DatetimeArray ,
@@ -1164,6 +1167,20 @@ def astype_td64_unit_conversion(
11641167 return result
11651168
11661169
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+
11671184def astype_nansafe (
11681185 arr : np .ndarray , dtype : DtypeObj , copy : bool = True , skipna : bool = False
11691186) -> ArrayLike :
@@ -1190,14 +1207,10 @@ def astype_nansafe(
11901207 flags = arr .flags
11911208 flat = arr .ravel ("K" )
11921209 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"
11941211 # error: Item "ExtensionArray" of "Union[ExtensionArray, ndarray]" has no
11951212 # 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]
12011214
12021215 # We get here with 0-dim from sparse
12031216 arr = np .atleast_1d (arr )
0 commit comments