Skip to content

Commit 592fc5d

Browse files
committed
return casted as bool
1 parent a4316e1 commit 592fc5d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pandas/core/dtypes/cast.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,9 +1921,11 @@ def np_can_hold_element(dtype: np.dtype, element: Any) -> Any:
19211921
# GH 57338
19221922
# Check boolean array set as object type
19231923
with np.errstate(invalid="ignore"):
1924-
casted = element.astype(dtype).astype("object")
1925-
element_object = element.astype("object")
1926-
comp = [i is j for i, j in zip(element_object, casted)]
1924+
casted = element.astype(dtype)
1925+
comp = [
1926+
i is j
1927+
for i, j in zip(element.astype("object"), casted.astype("object"))
1928+
]
19271929
if all(comp):
19281930
return casted
19291931
raise LossySetitemError

0 commit comments

Comments
 (0)