Skip to content

CLN: checks instead of try/except #27296

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

Merged
merged 2 commits into from
Jul 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3376,36 +3376,36 @@ def _putmask_smart(v, m, n):
# will work in the current dtype
try:
nn = n[m]

except TypeError:
# TypeError: only integer scalar arrays can be converted to a scalar index
pass
else:
# make sure that we have a nullable type
# if we have nulls
if not _isna_compat(v, nn[0]):
raise ValueError

# we ignore ComplexWarning here
with warnings.catch_warnings(record=True):
warnings.simplefilter("ignore", np.ComplexWarning)
nn_at = nn.astype(v.dtype)

# avoid invalid dtype comparisons
# between numbers & strings

# only compare integers/floats
# don't compare integers to datetimelikes
if not is_numeric_v_string_like(nn, nn_at) and (
is_float_dtype(nn.dtype)
or is_integer_dtype(nn.dtype)
and is_float_dtype(nn_at.dtype)
or is_integer_dtype(nn_at.dtype)
):
pass
elif is_numeric_v_string_like(nn, v):
# avoid invalid dtype comparisons
# between numbers & strings
pass
elif not (is_float_dtype(nn.dtype) or is_integer_dtype(nn.dtype)):
# only compare integers/floats
pass
elif not (is_float_dtype(v.dtype) or is_integer_dtype(v.dtype)):
# only compare integers/floats
pass
else:

# we ignore ComplexWarning here
with warnings.catch_warnings(record=True):
warnings.simplefilter("ignore", np.ComplexWarning)
nn_at = nn.astype(v.dtype)

comp = nn == nn_at
if is_list_like(comp) and comp.all():
nv = v.copy()
nv[m] = nn_at
return nv
except (ValueError, IndexError, TypeError, OverflowError):
pass

n = np.asarray(n)

Expand Down