|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 | 3 | import numbers
|
4 |
| -from typing import ( |
5 |
| - TYPE_CHECKING, |
6 |
| - overload, |
7 |
| -) |
| 4 | +from typing import TYPE_CHECKING |
8 | 5 |
|
9 | 6 | import numpy as np
|
10 | 7 |
|
|
13 | 10 | missing as libmissing,
|
14 | 11 | )
|
15 | 12 | from pandas._typing import (
|
16 |
| - ArrayLike, |
17 |
| - AstypeArg, |
18 | 13 | Dtype,
|
19 | 14 | DtypeObj,
|
20 |
| - npt, |
21 | 15 | type_t,
|
22 | 16 | )
|
23 | 17 |
|
24 | 18 | from pandas.core.dtypes.common import (
|
25 |
| - is_bool_dtype, |
26 |
| - is_float_dtype, |
27 |
| - is_integer_dtype, |
28 | 19 | is_list_like,
|
29 | 20 | is_numeric_dtype,
|
30 |
| - pandas_dtype, |
31 |
| -) |
32 |
| -from pandas.core.dtypes.dtypes import ( |
33 |
| - ExtensionDtype, |
34 |
| - register_extension_dtype, |
35 | 21 | )
|
| 22 | +from pandas.core.dtypes.dtypes import register_extension_dtype |
36 | 23 | from pandas.core.dtypes.missing import isna
|
37 | 24 |
|
38 | 25 | from pandas.core import ops
|
39 |
| -from pandas.core.arrays import ExtensionArray |
40 | 26 | from pandas.core.arrays.masked import (
|
41 | 27 | BaseMaskedArray,
|
42 | 28 | BaseMaskedDtype,
|
@@ -360,67 +346,6 @@ def _coerce_to_array(
|
360 | 346 | assert dtype == "boolean"
|
361 | 347 | return coerce_to_array(value, copy=copy)
|
362 | 348 |
|
363 |
| - @overload |
364 |
| - def astype(self, dtype: npt.DTypeLike, copy: bool = ...) -> np.ndarray: |
365 |
| - ... |
366 |
| - |
367 |
| - @overload |
368 |
| - def astype(self, dtype: ExtensionDtype, copy: bool = ...) -> ExtensionArray: |
369 |
| - ... |
370 |
| - |
371 |
| - @overload |
372 |
| - def astype(self, dtype: AstypeArg, copy: bool = ...) -> ArrayLike: |
373 |
| - ... |
374 |
| - |
375 |
| - def astype(self, dtype: AstypeArg, copy: bool = True) -> ArrayLike: |
376 |
| - |
377 |
| - """ |
378 |
| - Cast to a NumPy array or ExtensionArray with 'dtype'. |
379 |
| -
|
380 |
| - Parameters |
381 |
| - ---------- |
382 |
| - dtype : str or dtype |
383 |
| - Typecode or data-type to which the array is cast. |
384 |
| - copy : bool, default True |
385 |
| - Whether to copy the data, even if not necessary. If False, |
386 |
| - a copy is made only if the old dtype does not match the |
387 |
| - new dtype. |
388 |
| -
|
389 |
| - Returns |
390 |
| - ------- |
391 |
| - ndarray or ExtensionArray |
392 |
| - NumPy ndarray, BooleanArray or IntegerArray with 'dtype' for its dtype. |
393 |
| -
|
394 |
| - Raises |
395 |
| - ------ |
396 |
| - TypeError |
397 |
| - if incompatible type with an BooleanDtype, equivalent of same_kind |
398 |
| - casting |
399 |
| - """ |
400 |
| - dtype = pandas_dtype(dtype) |
401 |
| - |
402 |
| - if isinstance(dtype, ExtensionDtype): |
403 |
| - return super().astype(dtype, copy) |
404 |
| - |
405 |
| - if is_bool_dtype(dtype): |
406 |
| - # astype_nansafe converts np.nan to True |
407 |
| - if self._hasna: |
408 |
| - raise ValueError("cannot convert float NaN to bool") |
409 |
| - else: |
410 |
| - return self._data.astype(dtype, copy=copy) |
411 |
| - |
412 |
| - # for integer, error if there are missing values |
413 |
| - if is_integer_dtype(dtype) and self._hasna: |
414 |
| - raise ValueError("cannot convert NA to integer") |
415 |
| - |
416 |
| - # for float dtype, ensure we use np.nan before casting (numpy cannot |
417 |
| - # deal with pd.NA) |
418 |
| - na_value = self._na_value |
419 |
| - if is_float_dtype(dtype): |
420 |
| - na_value = np.nan |
421 |
| - # coerce |
422 |
| - return self.to_numpy(dtype=dtype, na_value=na_value, copy=False) |
423 |
| - |
424 | 349 | def _logical_method(self, other, op):
|
425 | 350 |
|
426 | 351 | assert op.__name__ in {"or_", "ror_", "and_", "rand_", "xor", "rxor"}
|
|
0 commit comments