Skip to content

Commit 079c403

Browse files
committed
more efficient check
1 parent aee48c9 commit 079c403

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pandas/core/dtypes/cast.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,9 +1919,9 @@ def np_can_hold_element(dtype: np.dtype, element: Any) -> Any:
19191919
return element
19201920
# GH 57338
19211921
# Check boolean array set as object type
1922-
comp = [lib.is_bool(e) for e in np.array([element]).ravel()]
1923-
if all(comp):
1924-
return element.astype("bool")
1922+
if tipo.kind == "O" and isinstance(element, np.ndarray):
1923+
if all(lib.is_bool(e) for e in element):
1924+
return element.astype("bool")
19251925
raise LossySetitemError
19261926

19271927
if lib.is_bool(element):

0 commit comments

Comments
 (0)