52
52
is_integer_dtype ,
53
53
is_list_like ,
54
54
is_object_dtype ,
55
- is_sparse ,
56
55
is_string_dtype ,
57
56
is_timedelta64_ns_dtype ,
58
57
)
58
+ from pandas .core .dtypes .dtypes import DatetimeTZDtype
59
59
from pandas .core .dtypes .generic import (
60
60
ABCExtensionArray ,
61
61
ABCIndex ,
@@ -549,12 +549,10 @@ def sanitize_array(
549
549
550
550
subarr = _sanitize_ndim (subarr , data , dtype , index )
551
551
552
- if not (is_extension_array_dtype (subarr .dtype ) or is_extension_array_dtype (dtype )):
553
- # error: Argument 1 to "_sanitize_str_dtypes" has incompatible type
554
- # "ExtensionArray"; expected "ndarray"
555
- subarr = _sanitize_str_dtypes (
556
- subarr , data , dtype , copy # type: ignore[arg-type]
557
- )
552
+ if not (
553
+ isinstance (subarr .dtype , ExtensionDtype ) or isinstance (dtype , ExtensionDtype )
554
+ ):
555
+ subarr = _sanitize_str_dtypes (subarr , data , dtype , copy )
558
556
559
557
is_object_or_str_dtype = is_object_dtype (dtype ) or is_string_dtype (dtype )
560
558
if is_object_dtype (subarr .dtype ) and not is_object_or_str_dtype :
@@ -599,7 +597,7 @@ def _sanitize_ndim(
599
597
600
598
601
599
def _sanitize_str_dtypes (
602
- result : np .ndarray , data , dtype : Optional [DtypeObj ], copy : bool
600
+ result : np .ndarray , data , dtype : Optional [np . dtype ], copy : bool
603
601
) -> np .ndarray :
604
602
"""
605
603
Ensure we have a dtype that is supported by pandas.
@@ -613,11 +611,7 @@ def _sanitize_str_dtypes(
613
611
# GH#19853: If data is a scalar, result has already the result
614
612
if not lib .is_scalar (data ):
615
613
if not np .all (isna (data )):
616
- # error: Argument "dtype" to "array" has incompatible type
617
- # "Union[dtype[Any], ExtensionDtype, None]"; expected "Union[dtype[Any],
618
- # None, type, _SupportsDType, str, Union[Tuple[Any, int], Tuple[Any,
619
- # Union[int, Sequence[int]]], List[Any], _DTypeDict, Tuple[Any, Any]]]"
620
- data = np .array (data , dtype = dtype , copy = False ) # type: ignore[arg-type]
614
+ data = np .array (data , dtype = dtype , copy = False )
621
615
result = np .array (data , dtype = object , copy = copy )
622
616
return result
623
617
@@ -666,7 +660,7 @@ def _try_cast(
666
660
):
667
661
return arr
668
662
669
- if isinstance (dtype , ExtensionDtype ) and ( dtype . kind != "M" or is_sparse (dtype ) ):
663
+ if isinstance (dtype , ExtensionDtype ) and not isinstance (dtype , DatetimeTZDtype ):
670
664
# create an extension array from its dtype
671
665
# DatetimeTZ case needs to go through maybe_cast_to_datetime but
672
666
# SparseDtype does not
0 commit comments