|
20 | 20 | from pandas.util._validators import validate_fillna_kwargs
|
21 | 21 |
|
22 | 22 | from pandas.core.dtypes.cast import maybe_cast_to_extension_array
|
23 |
| -from pandas.core.dtypes.common import is_array_like, is_list_like |
| 23 | +from pandas.core.dtypes.common import is_array_like, is_list_like, pandas_dtype |
24 | 24 | from pandas.core.dtypes.dtypes import ExtensionDtype
|
25 | 25 | from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries
|
26 | 26 | from pandas.core.dtypes.missing import isna
|
@@ -176,7 +176,7 @@ def _from_sequence(cls, scalars, dtype=None, copy=False):
|
176 | 176 | ----------
|
177 | 177 | scalars : Sequence
|
178 | 178 | Each element will be an instance of the scalar type for this
|
179 |
| - array, ``cls.dtype.type``. |
| 179 | + array, ``cls.dtype.type`` or be converted into this type in this method. |
180 | 180 | dtype : dtype, optional
|
181 | 181 | Construct for this particular dtype. This should be a Dtype
|
182 | 182 | compatible with the ExtensionArray.
|
@@ -213,29 +213,6 @@ def _from_sequence_of_strings(cls, strings, dtype=None, copy=False):
|
213 | 213 | """
|
214 | 214 | raise AbstractMethodError(cls)
|
215 | 215 |
|
216 |
| - @classmethod |
217 |
| - def _from_sequence_of_any_type(cls, scalars, dtype=None, copy=False): |
218 |
| - """ |
219 |
| - Construct a new ExtensionArray from a sequence of unknown types of scalars. |
220 |
| -
|
221 |
| - .. versionadded:: 1.1.0 |
222 |
| -
|
223 |
| - Parameters |
224 |
| - ---------- |
225 |
| - scalars : Sequence |
226 |
| - Each element can be an instance of unknown scalar types. |
227 |
| - dtype : dtype, optional |
228 |
| - Construct for this particular dtype. This should be a Dtype |
229 |
| - compatible with the ExtensionArray. |
230 |
| - copy : bool, default False |
231 |
| - If True, copy the underlying data. |
232 |
| -
|
233 |
| - Returns |
234 |
| - ------- |
235 |
| - ExtensionArray |
236 |
| - """ |
237 |
| - return cls._from_sequence(scalars, dtype=dtype, copy=copy) |
238 |
| - |
239 | 216 | @classmethod
|
240 | 217 | def _from_factorized(cls, values, original):
|
241 | 218 | """
|
@@ -454,6 +431,11 @@ def astype(self, dtype, copy=True):
|
454 | 431 | array : ndarray
|
455 | 432 | NumPy ndarray with 'dtype' for its dtype.
|
456 | 433 | """
|
| 434 | + from pandas.core.arrays.string_ import StringDtype |
| 435 | + |
| 436 | + dtype = pandas_dtype(dtype) |
| 437 | + if isinstance(dtype, StringDtype): |
| 438 | + return dtype.construct_array_type()._from_sequence(self, copy=False) |
457 | 439 | return np.array(self, dtype=dtype, copy=copy)
|
458 | 440 |
|
459 | 441 | def isna(self) -> ArrayLike:
|
|
0 commit comments