Skip to content

Commit 1050d9e

Browse files
committed
rewrite categorical check in Block.astype
1 parent 57817a4 commit 1050d9e

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

pandas/core/internals/blocks.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -588,18 +588,12 @@ def astype(self, dtype, copy: bool = False, errors: str = "raise"):
588588
dtype = pandas_dtype(dtype)
589589

590590
# may need to convert to categorical
591-
if is_categorical_dtype(dtype):
592-
593-
if is_categorical_dtype(self.values.dtype):
594-
# GH 10696/18593: update an existing categorical efficiently
595-
return self.make_block(
596-
Categorical.from_codes(
597-
self.cat.codes, categories=self.cat.categories.astype(dtype)
598-
),
599-
copy=copy,
591+
if is_categorical_dtype(self.values.dtype):
592+
return self.make_block(
593+
Categorical.from_codes(
594+
self.values.codes, categories=self.values.categories.astype(dtype)
600595
)
601-
602-
return self.make_block(Categorical(self.values, dtype=dtype))
596+
)
603597

604598
dtype = pandas_dtype(dtype)
605599

0 commit comments

Comments
 (0)