@@ -561,11 +561,9 @@ def astype(self, dtype: AstypeArg, copy: bool = True) -> ArrayLike:
561561 Returns
562562 -------
563563 array : np.ndarray or ExtensionArray
564- An ExtensionArray if dtype is StringDtype,
565- or same as that of underlying array.
564+ An ExtensionArray if dtype is ExtensionDtype,
566565 Otherwise a NumPy ndarray with 'dtype' for its dtype.
567566 """
568- from pandas .core .arrays .string_ import StringDtype
569567
570568 dtype = pandas_dtype (dtype )
571569 if is_dtype_equal (dtype , self .dtype ):
@@ -574,16 +572,11 @@ def astype(self, dtype: AstypeArg, copy: bool = True) -> ArrayLike:
574572 else :
575573 return self .copy ()
576574
577- # FIXME: Really hard-code here?
578- if isinstance (dtype , StringDtype ):
579- # allow conversion to StringArrays
580- return dtype .construct_array_type ()._from_sequence (self , copy = False )
575+ if isinstance (dtype , ExtensionDtype ):
576+ cls = dtype .construct_array_type ()
577+ return cls ._from_sequence (self , dtype = dtype , copy = copy )
581578
582- # error: Argument "dtype" to "array" has incompatible type
583- # "Union[ExtensionDtype, dtype[Any]]"; expected "Union[dtype[Any], None, type,
584- # _SupportsDType, str, Union[Tuple[Any, int], Tuple[Any, Union[int,
585- # Sequence[int]]], List[Any], _DTypeDict, Tuple[Any, Any]]]"
586- return np .array (self , dtype = dtype , copy = copy ) # type: ignore[arg-type]
579+ return np .array (self , dtype = dtype , copy = copy )
587580
588581 def isna (self ) -> np .ndarray | ExtensionArraySupportsAnyAll :
589582 """
0 commit comments