Skip to content

Commit 6366303

Browse files
committed
fixed comparison with 1 and 0
1 parent 50f9a20 commit 6366303

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pandas/core/dtypes/cast.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,9 +1921,10 @@ 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)
1925-
comp = casted == element
1926-
if comp.all():
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)]
1927+
if all(comp):
19271928
return casted
19281929
raise LossySetitemError
19291930

0 commit comments

Comments
 (0)