5252 is_integer_dtype ,
5353 is_list_like ,
5454 is_object_dtype ,
55- is_sparse ,
5655 is_string_dtype ,
5756 is_timedelta64_ns_dtype ,
5857)
58+ from pandas .core .dtypes .dtypes import DatetimeTZDtype
5959from pandas .core .dtypes .generic import (
6060 ABCExtensionArray ,
6161 ABCIndex ,
@@ -549,12 +549,10 @@ def sanitize_array(
549549
550550 subarr = _sanitize_ndim (subarr , data , dtype , index )
551551
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 )
558556
559557 is_object_or_str_dtype = is_object_dtype (dtype ) or is_string_dtype (dtype )
560558 if is_object_dtype (subarr .dtype ) and not is_object_or_str_dtype :
@@ -599,7 +597,7 @@ def _sanitize_ndim(
599597
600598
601599def _sanitize_str_dtypes (
602- result : np .ndarray , data , dtype : Optional [DtypeObj ], copy : bool
600+ result : np .ndarray , data , dtype : Optional [np . dtype ], copy : bool
603601) -> np .ndarray :
604602 """
605603 Ensure we have a dtype that is supported by pandas.
@@ -613,11 +611,7 @@ def _sanitize_str_dtypes(
613611 # GH#19853: If data is a scalar, result has already the result
614612 if not lib .is_scalar (data ):
615613 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 )
621615 result = np .array (data , dtype = object , copy = copy )
622616 return result
623617
@@ -666,7 +660,7 @@ def _try_cast(
666660 ):
667661 return arr
668662
669- if isinstance (dtype , ExtensionDtype ) and ( dtype . kind != "M" or is_sparse (dtype ) ):
663+ if isinstance (dtype , ExtensionDtype ) and not isinstance (dtype , DatetimeTZDtype ):
670664 # create an extension array from its dtype
671665 # DatetimeTZ case needs to go through maybe_cast_to_datetime but
672666 # SparseDtype does not
0 commit comments