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 e3a3a4a commit 5dba4ccCopy full SHA for 5dba4cc
pandas/core/dtypes/cast.py
@@ -1918,7 +1918,17 @@ def np_can_hold_element(dtype: np.dtype, element: Any) -> Any:
1918
# i.e. there are pd.NA elements
1919
raise LossySetitemError
1920
return element
1921
+ with np.errstate(invalid="ignore"):
1922
+ # We check afterwards if cast was losslessly, so no need to show
1923
+ # the warning
1924
+ casted = element.astype(dtype)
1925
+ comp = casted == element
1926
+ if comp.all():
1927
+ # Return the casted values bc they can be passed to
1928
+ # np.putmask, whereas the raw values cannot.
1929
+ return casted
1930
1931
+
1932
if lib.is_bool(element):
1933
1934
0 commit comments