Skip to content

Commit 09b676c

Browse files
mroeschkeyehoshuadimarsky
authored andcommitted
CI/TST: Don't require length for construct_1d_arraylike_from_scalar cast to float64 (pandas-dev#47393)
1 parent f74687c commit 09b676c

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

pandas/core/construction.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,10 @@ def sanitize_array(
556556
if dtype is not None and is_float_dtype(data.dtype) and is_integer_dtype(dtype):
557557
# possibility of nan -> garbage
558558
try:
559-
subarr = _try_cast(data, dtype, copy, True)
559+
# GH 47391 numpy > 1.24 will raise a RuntimeError for nan -> int
560+
# casting aligning with IntCastingNaNError below
561+
with np.errstate(invalid="ignore"):
562+
subarr = _try_cast(data, dtype, copy, True)
560563
except IntCastingNaNError:
561564
warnings.warn(
562565
"In a future version, passing float-dtype values containing NaN "

pandas/core/dtypes/cast.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,9 @@ def construct_1d_arraylike_from_scalar(
17091709
value = _maybe_unbox_datetimelike_tz_deprecation(value, dtype)
17101710

17111711
subarr = np.empty(length, dtype=dtype)
1712-
subarr.fill(value)
1712+
if length:
1713+
# GH 47391: numpy > 1.24 will raise filling np.nan into int dtypes
1714+
subarr.fill(value)
17131715

17141716
return subarr
17151717

pandas/core/reshape/merge.py

+18-14
Original file line numberDiff line numberDiff line change
@@ -1200,23 +1200,27 @@ def _maybe_coerce_merge_keys(self) -> None:
12001200

12011201
# check whether ints and floats
12021202
elif is_integer_dtype(rk.dtype) and is_float_dtype(lk.dtype):
1203-
if not (lk == lk.astype(rk.dtype))[~np.isnan(lk)].all():
1204-
warnings.warn(
1205-
"You are merging on int and float "
1206-
"columns where the float values "
1207-
"are not equal to their int representation.",
1208-
UserWarning,
1209-
)
1203+
# GH 47391 numpy > 1.24 will raise a RuntimeError for nan -> int
1204+
with np.errstate(invalid="ignore"):
1205+
if not (lk == lk.astype(rk.dtype))[~np.isnan(lk)].all():
1206+
warnings.warn(
1207+
"You are merging on int and float "
1208+
"columns where the float values "
1209+
"are not equal to their int representation.",
1210+
UserWarning,
1211+
)
12101212
continue
12111213

12121214
elif is_float_dtype(rk.dtype) and is_integer_dtype(lk.dtype):
1213-
if not (rk == rk.astype(lk.dtype))[~np.isnan(rk)].all():
1214-
warnings.warn(
1215-
"You are merging on int and float "
1216-
"columns where the float values "
1217-
"are not equal to their int representation.",
1218-
UserWarning,
1219-
)
1215+
# GH 47391 numpy > 1.24 will raise a RuntimeError for nan -> int
1216+
with np.errstate(invalid="ignore"):
1217+
if not (rk == rk.astype(lk.dtype))[~np.isnan(rk)].all():
1218+
warnings.warn(
1219+
"You are merging on int and float "
1220+
"columns where the float values "
1221+
"are not equal to their int representation.",
1222+
UserWarning,
1223+
)
12201224
continue
12211225

12221226
# let's infer and see if we are ok

0 commit comments

Comments
 (0)