Skip to content

Commit c38f1c8

Browse files
committed
BUG: add cases to coerce_to_target_dtype
1 parent a9fbc33 commit c38f1c8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pandas/core/internals/blocks.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,10 @@ def coerce_to_target_dtype(self, other):
11301130
if is_dtype_equal(self.dtype, dtype):
11311131
return self
11321132

1133-
if self.is_bool or is_object_dtype(dtype) or is_bool_dtype(dtype):
1133+
if is_extension_array_dtype(self.dtype) and not is_categorical_dtype(dtype):
1134+
dtype = self.dtype
1135+
1136+
elif self.is_bool or is_object_dtype(dtype) or is_bool_dtype(dtype):
11341137
# we don't upcast to bool
11351138
return self.astype(object)
11361139

@@ -1174,6 +1177,9 @@ def coerce_to_target_dtype(self, other):
11741177
f"possible recursion in coerce_to_target_dtype: {self} {other}"
11751178
)
11761179

1180+
if is_categorical_dtype(dtype) or self.is_datetime:
1181+
return self.astype(object)
1182+
11771183
try:
11781184
return self.astype(dtype)
11791185
except (ValueError, TypeError, OverflowError):

0 commit comments

Comments
 (0)