|
1 | 1 | import numbers
|
2 |
| -from typing import TYPE_CHECKING, List, Optional, Tuple, Type, Union |
| 2 | +from typing import TYPE_CHECKING, List, Optional, Dict, Tuple, Type, Union |
3 | 3 | import warnings
|
4 | 4 |
|
5 | 5 | import numpy as np
|
@@ -442,17 +442,20 @@ def astype(self, dtype, copy: bool = True) -> ArrayLike:
|
442 | 442 | if incompatible type with an IntegerDtype, equivalent of same_kind
|
443 | 443 | casting
|
444 | 444 | """
|
445 |
| - from pandas.core.arrays.boolean import BooleanArray, BooleanDtype |
| 445 | + from pandas.core.arrays.boolean import BooleanDtype |
| 446 | + from pandas.core.arrays.string_ import StringDtype |
446 | 447 |
|
447 | 448 | dtype = pandas_dtype(dtype)
|
448 | 449 |
|
449 | 450 | # if we are astyping to an existing IntegerDtype we can fastpath
|
450 | 451 | if isinstance(dtype, _IntegerDtype):
|
451 | 452 | result = self._data.astype(dtype.numpy_dtype, copy=False)
|
452 |
| - return type(self)(result, mask=self._mask, copy=False) |
| 453 | + return dtype.construct_array_type()(result, mask=self._mask, copy=False) |
453 | 454 | elif isinstance(dtype, BooleanDtype):
|
454 | 455 | result = self._data.astype("bool", copy=False)
|
455 |
| - return BooleanArray(result, mask=self._mask, copy=False) |
| 456 | + return dtype.construct_array_type()(result, mask=self._mask, copy=False) |
| 457 | + elif isinstance(dtype, StringDtype): |
| 458 | + return dtype.construct_array_type()._from_sequence(self, copy=False) |
456 | 459 |
|
457 | 460 | # coerce
|
458 | 461 | if is_float_dtype(dtype):
|
@@ -722,7 +725,7 @@ class UInt64Dtype(_IntegerDtype):
|
722 | 725 | __doc__ = _dtype_docstring.format(dtype="uint64")
|
723 | 726 |
|
724 | 727 |
|
725 |
| -_dtypes = { |
| 728 | +_dtypes: Dict[str, _IntegerDtype] = { |
726 | 729 | "int8": Int8Dtype(),
|
727 | 730 | "int16": Int16Dtype(),
|
728 | 731 | "int32": Int32Dtype(),
|
|
0 commit comments