Skip to content

Commit 26860c9

Browse files
committed
BUG: add cases to coerce_to_target_dtype
1 parent 851ae5a commit 26860c9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pandas/core/internals/blocks.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,10 @@ def coerce_to_target_dtype(self, other):
11651165
if is_dtype_equal(self.dtype, dtype):
11661166
return self
11671167

1168-
if self.is_bool or is_object_dtype(dtype) or is_bool_dtype(dtype):
1168+
if is_extension_array_dtype(self.dtype) and not is_categorical_dtype(dtype):
1169+
dtype = self.dtype
1170+
1171+
elif self.is_bool or is_object_dtype(dtype) or is_bool_dtype(dtype):
11691172
# we don't upcast to bool
11701173
return self.astype(object)
11711174

@@ -1209,6 +1212,9 @@ def coerce_to_target_dtype(self, other):
12091212
f"possible recursion in coerce_to_target_dtype: {self} {other}"
12101213
)
12111214

1215+
if is_categorical_dtype(dtype) or self.is_datetime:
1216+
return self.astype(object)
1217+
12121218
try:
12131219
return self.astype(dtype)
12141220
except (ValueError, TypeError, OverflowError):

0 commit comments

Comments
 (0)