File tree 2 files changed +18
-8
lines changed
2 files changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -225,14 +225,27 @@ def count_not_none(*args) -> int:
225
225
return sum (x is not None for x in args )
226
226
227
227
228
- def asarray_tuplesafe (values , dtype : NpDtype | None = None ) -> np .ndarray :
228
+ @overload
229
+ def asarray_tuplesafe (
230
+ values : ArrayLike | list | tuple | zip , dtype : NpDtype | None = ...
231
+ ) -> np .ndarray :
232
+ # ExtensionArray can only be returned when values is an Index, all other iterables
233
+ # will return np.ndarray. Unfortunately "all other" cannot be encoded in a type
234
+ # signature, so instead we special-case some common types.
235
+ ...
236
+
237
+
238
+ @overload
239
+ def asarray_tuplesafe (values : Iterable , dtype : NpDtype | None = ...) -> ArrayLike :
240
+ ...
241
+
242
+
243
+ def asarray_tuplesafe (values : Iterable , dtype : NpDtype | None = None ) -> ArrayLike :
229
244
230
245
if not (isinstance (values , (list , tuple )) or hasattr (values , "__array__" )):
231
246
values = list (values )
232
247
elif isinstance (values , ABCIndex ):
233
- # error: Incompatible return value type (got "Union[ExtensionArray, ndarray]",
234
- # expected "ndarray")
235
- return values ._values # type: ignore[return-value]
248
+ return values ._values
236
249
237
250
if isinstance (values , list ) and dtype in [np .object_ , object ]:
238
251
return construct_1d_object_array_from_listlike (values )
Original file line number Diff line number Diff line change @@ -555,10 +555,7 @@ def __new__(
555
555
subarr = com .asarray_tuplesafe (data , dtype = _dtype_obj )
556
556
if dtype is None :
557
557
# with e.g. a list [1, 2, 3] casting to numeric is _not_ deprecated
558
- # error: Incompatible types in assignment (expression has type
559
- # "Union[ExtensionArray, ndarray[Any, Any]]", variable has type
560
- # "ndarray[Any, Any]")
561
- subarr = _maybe_cast_data_without_dtype ( # type: ignore[assignment]
558
+ subarr = _maybe_cast_data_without_dtype (
562
559
subarr , cast_numeric_deprecated = False
563
560
)
564
561
dtype = subarr .dtype
You can’t perform that action at this time.
0 commit comments