|
50 | 50 | pandas_dtype,
|
51 | 51 | )
|
52 | 52 | from pandas.core.dtypes.concat import concat_categorical, concat_datetime
|
53 |
| -from pandas.core.dtypes.dtypes import CategoricalDtype, ExtensionDtype |
| 53 | +from pandas.core.dtypes.dtypes import ExtensionDtype |
54 | 54 | from pandas.core.dtypes.generic import (
|
55 | 55 | ABCDataFrame,
|
56 | 56 | ABCExtensionArray,
|
@@ -183,21 +183,6 @@ def is_datelike(self) -> bool:
|
183 | 183 | """ return True if I am a non-datelike """
|
184 | 184 | return self.is_datetime or self.is_timedelta
|
185 | 185 |
|
186 |
| - def is_categorical_astype(self, dtype) -> bool: |
187 |
| - """ |
188 |
| - validate that we have a astypeable to categorical, |
189 |
| - returns a boolean if we are a categorical |
190 |
| - """ |
191 |
| - if dtype is Categorical or dtype is CategoricalDtype: |
192 |
| - # this is a pd.Categorical, but is not |
193 |
| - # a valid type for astypeing |
194 |
| - raise TypeError(f"invalid type {dtype} for astype") |
195 |
| - |
196 |
| - elif is_categorical_dtype(dtype): |
197 |
| - return True |
198 |
| - |
199 |
| - return False |
200 |
| - |
201 | 186 | def external_values(self):
|
202 | 187 | """
|
203 | 188 | The array that Series.values returns (public attribute).
|
@@ -565,7 +550,7 @@ def astype(self, dtype, copy: bool = False, errors: str = "raise"):
|
565 | 550 | raise TypeError(msg)
|
566 | 551 |
|
567 | 552 | # may need to convert to categorical
|
568 |
| - if self.is_categorical_astype(dtype): |
| 553 | + if is_categorical_dtype(dtype): |
569 | 554 |
|
570 | 555 | if is_categorical_dtype(self.values):
|
571 | 556 | # GH 10696/18593: update an existing categorical efficiently
|
|
0 commit comments