Skip to content

Commit 967a218

Browse files
committed
feedback: move change core/generic -> internals
1 parent c7c439b commit 967a218

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

pandas/core/generic.py

-7
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
ensure_str,
6767
is_bool,
6868
is_bool_dtype,
69-
is_categorical_dtype,
7069
is_datetime64_any_dtype,
7170
is_datetime64tz_dtype,
7271
is_dict_like,
@@ -5795,12 +5794,6 @@ def astype(
57955794
for i in range(len(self.columns))
57965795
]
57975796

5798-
elif is_categorical_dtype(self):
5799-
new_data = pd.Categorical.from_codes(
5800-
self.cat.codes, categories=self.cat.categories.astype(dtype)
5801-
)
5802-
return self._constructor(new_data).__finalize__(self, method="astype")
5803-
58045797
else:
58055798
# else, only a single dtype is given
58065799
new_data = self._mgr.astype(dtype=dtype, copy=copy, errors=errors)

pandas/core/internals/blocks.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,12 @@ def astype(self, dtype, copy: bool = False, errors: str = "raise"):
592592

593593
if is_categorical_dtype(self.values.dtype):
594594
# GH 10696/18593: update an existing categorical efficiently
595-
return self.make_block(self.values.astype(dtype, copy=copy))
595+
return self.make_block(
596+
Categorical.from_codes(
597+
self.cat.codes, categories=self.cat.categories.astype(dtype)
598+
),
599+
copy=copy,
600+
)
596601

597602
return self.make_block(Categorical(self.values, dtype=dtype))
598603

0 commit comments

Comments
 (0)