Skip to content

Commit b4cf203

Browse files
committed
avoid invalid dtype comparision warning
1 parent 2661b79 commit b4cf203

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

pandas/_libs/index.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ cpdef convert_scalar(ndarray arr, object value):
535535
return Timedelta(value).value
536536
raise ValueError("cannot set a Timedelta with a non-timedelta")
537537

538-
if (issubclass(arr.dtype.type, (np.integer, np.floating, np.complex)) and not
539-
issubclass(arr.dtype.type, np.bool_)):
538+
if (issubclass(arr.dtype.type, (np.integer, np.floating, np.complex)) and
539+
not issubclass(arr.dtype.type, np.bool_)):
540540
if util.is_bool_object(value):
541541
raise ValueError('Cannot assign bool to float/integer series')
542542

pandas/core/internals.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -4940,11 +4940,18 @@ def _putmask_smart(v, m, n):
49404940

49414941
# avoid invalid dtype comparisons
49424942
if not is_numeric_v_string_like(nn, nn_at):
4943-
comp = (nn == nn_at)
4944-
if is_list_like(comp) and comp.all():
4945-
nv = v.copy()
4946-
nv[m] = nn_at
4947-
return nv
4943+
4944+
# only compare integers/floats
4945+
# don't compare integers to datetimelikes
4946+
if (is_float_dtype(nn.dtype) or
4947+
is_integer_dtype(nn.dtype) and
4948+
is_float_dtype(nn_at.dtype) or
4949+
is_integer_dtype(nn_at.dtype)):
4950+
comp = (nn == nn_at)
4951+
if is_list_like(comp) and comp.all():
4952+
nv = v.copy()
4953+
nv[m] = nn_at
4954+
return nv
49484955
except (ValueError, IndexError, TypeError):
49494956
pass
49504957

0 commit comments

Comments
 (0)