We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 50f9a20 commit 6366303Copy full SHA for 6366303
pandas/core/dtypes/cast.py
@@ -1921,9 +1921,10 @@ def np_can_hold_element(dtype: np.dtype, element: Any) -> Any:
1921
# GH 57338
1922
# Check boolean array set as object type
1923
with np.errstate(invalid="ignore"):
1924
- casted = element.astype(dtype)
1925
- comp = casted == element
1926
- if comp.all():
+ casted = element.astype(dtype).astype("object")
+ element_object = element.astype("object")
+ comp = [i is j for i, j in zip(element_object, casted)]
1927
+ if all(comp):
1928
return casted
1929
raise LossySetitemError
1930
0 commit comments