@@ -561,11 +561,9 @@ def astype(self, dtype: AstypeArg, copy: bool = True) -> ArrayLike:
561
561
Returns
562
562
-------
563
563
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,
566
565
Otherwise a NumPy ndarray with 'dtype' for its dtype.
567
566
"""
568
- from pandas .core .arrays .string_ import StringDtype
569
567
570
568
dtype = pandas_dtype (dtype )
571
569
if is_dtype_equal (dtype , self .dtype ):
@@ -574,16 +572,11 @@ def astype(self, dtype: AstypeArg, copy: bool = True) -> ArrayLike:
574
572
else :
575
573
return self .copy ()
576
574
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 )
581
578
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 )
587
580
588
581
def isna (self ) -> np .ndarray | ExtensionArraySupportsAnyAll :
589
582
"""
0 commit comments