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 a4316e1 commit 592fc5dCopy full SHA for 592fc5d
pandas/core/dtypes/cast.py
@@ -1921,9 +1921,11 @@ 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).astype("object")
1925
- element_object = element.astype("object")
1926
- comp = [i is j for i, j in zip(element_object, casted)]
+ casted = element.astype(dtype)
+ comp = [
+ i is j
1927
+ for i, j in zip(element.astype("object"), casted.astype("object"))
1928
+ ]
1929
if all(comp):
1930
return casted
1931
raise LossySetitemError
0 commit comments