Skip to content

Commit 0fb9140

Browse files
committed
rebase and use _update_dtype
1 parent 375cdc9 commit 0fb9140

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

pandas/core/categorical.py

+3-15
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
is_categorical_dtype,
2828
is_list_like, is_sequence,
2929
is_scalar,
30-
is_dict_like,
31-
pandas_dtype)
30+
is_dict_like)
3231
from pandas.core.common import is_null_slice, _maybe_box_datetimelike
3332

3433
from pandas.core.algorithms import factorize, take_1d, unique1d
@@ -436,22 +435,11 @@ def astype(self, dtype, copy=True):
436435
.. versionadded:: 0.19.0
437436
438437
"""
439-
if isinstance(dtype, compat.string_types) and dtype == 'category':
440-
# GH 18593: astype('category') should not change anything
441-
return self.copy() if copy else self
442-
443-
dtype = pandas_dtype(dtype)
444438
if is_categorical_dtype(dtype):
445-
# GH 18593: keep current categories if None (ordered can't be None)
446-
if dtype.categories is None:
447-
new_categories = self.categories
448-
else:
449-
new_categories = dtype.categories
450-
dtype = CategoricalDtype(new_categories, dtype.ordered)
451-
439+
# GH 10696/18593
440+
dtype = self.dtype._update_dtype(dtype)
452441
self = self.copy() if copy else self
453442
if dtype == self.dtype:
454-
# fastpath if dtypes are equal
455443
return self
456444
return self._set_dtype(dtype)
457445
return np.array(self, dtype=dtype, copy=copy)

pandas/core/internals.py

-1
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,6 @@ def _astype(self, dtype, copy=False, errors='raise', values=None,
573573
raise TypeError(msg)
574574

575575
# may need to convert to categorical
576-
# this is only called for non-categoricals
577576
if self.is_categorical_astype(dtype):
578577

579578
# deprecated 17636

0 commit comments

Comments
 (0)