Skip to content

Commit e62b62b

Browse files
jbrockmendeljreback
authored andcommitted
CLN: checks instead of try/except (#27296)
1 parent 8efbe12 commit e62b62b

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

pandas/core/internals/blocks.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3376,36 +3376,36 @@ def _putmask_smart(v, m, n):
33763376
# will work in the current dtype
33773377
try:
33783378
nn = n[m]
3379-
3379+
except TypeError:
3380+
# TypeError: only integer scalar arrays can be converted to a scalar index
3381+
pass
3382+
else:
33803383
# make sure that we have a nullable type
33813384
# if we have nulls
33823385
if not _isna_compat(v, nn[0]):
3383-
raise ValueError
3384-
3385-
# we ignore ComplexWarning here
3386-
with warnings.catch_warnings(record=True):
3387-
warnings.simplefilter("ignore", np.ComplexWarning)
3388-
nn_at = nn.astype(v.dtype)
3389-
3390-
# avoid invalid dtype comparisons
3391-
# between numbers & strings
3392-
3393-
# only compare integers/floats
3394-
# don't compare integers to datetimelikes
3395-
if not is_numeric_v_string_like(nn, nn_at) and (
3396-
is_float_dtype(nn.dtype)
3397-
or is_integer_dtype(nn.dtype)
3398-
and is_float_dtype(nn_at.dtype)
3399-
or is_integer_dtype(nn_at.dtype)
3400-
):
3386+
pass
3387+
elif is_numeric_v_string_like(nn, v):
3388+
# avoid invalid dtype comparisons
3389+
# between numbers & strings
3390+
pass
3391+
elif not (is_float_dtype(nn.dtype) or is_integer_dtype(nn.dtype)):
3392+
# only compare integers/floats
3393+
pass
3394+
elif not (is_float_dtype(v.dtype) or is_integer_dtype(v.dtype)):
3395+
# only compare integers/floats
3396+
pass
3397+
else:
3398+
3399+
# we ignore ComplexWarning here
3400+
with warnings.catch_warnings(record=True):
3401+
warnings.simplefilter("ignore", np.ComplexWarning)
3402+
nn_at = nn.astype(v.dtype)
34013403

34023404
comp = nn == nn_at
34033405
if is_list_like(comp) and comp.all():
34043406
nv = v.copy()
34053407
nv[m] = nn_at
34063408
return nv
3407-
except (ValueError, IndexError, TypeError, OverflowError):
3408-
pass
34093409

34103410
n = np.asarray(n)
34113411

0 commit comments

Comments
 (0)