Skip to content

Commit 550d68d

Browse files
committed
Move block creation to after we've check for exact match in shape
1 parent a23b3c9 commit 550d68d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

pandas/core/internals/blocks.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -828,14 +828,6 @@ def setitem(self, indexer, value):
828828
if lib.is_scalar(value):
829829
value = convert_scalar(values, value)
830830

831-
if (
832-
hasattr(value, "dtype")
833-
and self.is_categorical_astype(value.dtype)
834-
and not is_categorical_dtype(values)
835-
):
836-
values[indexer] = value
837-
return self.make_block(Categorical(self.values, dtype=value.dtype))
838-
839831
else:
840832
# current dtype cannot store value, coerce to common dtype
841833
find_dtype = False
@@ -890,6 +882,14 @@ def setitem(self, indexer, value):
890882
and arr_value.size == values.size
891883
):
892884
values[indexer] = value
885+
886+
if self.is_categorical_astype(arr_value.dtype) and not is_categorical_dtype(
887+
values
888+
):
889+
# GH25495 - If the current dtype is not categorical,
890+
# we need to create a new categorical block
891+
return self.make_block(Categorical(self.values, dtype=arr_value.dtype))
892+
893893
try:
894894

895895
values = values.astype(arr_value.dtype)

0 commit comments

Comments
 (0)