Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Creation of UInt64 column with 18446744073709551615 throws RuntimeWarning #60214

Closed
wants to merge 18 commits into from
Closed
12 changes: 9 additions & 3 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
maybe_cast_to_integer_array,
maybe_convert_platform,
maybe_infer_to_datetimelike,
maybe_promote,
)
from pandas.core.dtypes.common import (
ensure_object,
Expand Down Expand Up @@ -513,10 +512,17 @@ def sanitize_masked_array(data: ma.MaskedArray) -> np.ndarray:
"""
mask = ma.getmaskarray(data)
if mask.any():
dtype, fill_value = maybe_promote(data.dtype, np.nan)
dtype = cast(np.dtype, dtype)
dtype = cast(np.dtype, data.dtype)
data = ma.asarray(data.astype(dtype, copy=True))
data.soften_mask() # set hardmask False if it was True

if np.issubdtype(dtype, np.integer):
fill_value: int | float | None = np.iinfo(dtype).min
lfffkh marked this conversation as resolved.
Show resolved Hide resolved
elif np.issubdtype(dtype, np.floating):
fill_value = np.nan
else:
fill_value = None

data[mask] = fill_value
else:
data = data.copy()
Expand Down
Loading