diff --git a/pandas/core/computation/expressions.py b/pandas/core/computation/expressions.py index 90bb12b4cd727..46bc762e1a0b3 100644 --- a/pandas/core/computation/expressions.py +++ b/pandas/core/computation/expressions.py @@ -107,15 +107,12 @@ def _evaluate_numexpr(op, op_str, a, b, reversed=False): a_value = getattr(a, "values", a) b_value = getattr(b, "values", b) - try: - result = ne.evaluate( - "a_value {op} b_value".format(op=op_str), - local_dict={"a_value": a_value, "b_value": b_value}, - casting="safe", - ) - except ValueError as detail: - if "unknown type object" in str(detail): - pass + + result = ne.evaluate( + "a_value {op} b_value".format(op=op_str), + local_dict={"a_value": a_value, "b_value": b_value}, + casting="safe", + ) if _TEST_MODE: _store_test_result(result is not None) @@ -140,21 +137,15 @@ def _where_numexpr(cond, a, b): a_value = getattr(a, "values", a) b_value = getattr(b, "values", b) - try: - result = ne.evaluate( - "where(cond_value, a_value, b_value)", - local_dict={ - "cond_value": cond_value, - "a_value": a_value, - "b_value": b_value, - }, - casting="safe", - ) - except ValueError as detail: - if "unknown type object" in str(detail): - pass - except Exception as detail: - raise TypeError(str(detail)) + result = ne.evaluate( + "where(cond_value, a_value, b_value)", + local_dict={ + "cond_value": cond_value, + "a_value": a_value, + "b_value": b_value, + }, + casting="safe", + ) if result is None: result = _where_standard(cond, a, b) @@ -167,11 +158,10 @@ def _where_numexpr(cond, a, b): def _has_bool_dtype(x): + if isinstance(x, ABCDataFrame): + return "bool" in x.dtypes try: - if isinstance(x, ABCDataFrame): - return "bool" in x.dtypes - else: - return x.dtype == bool + return x.dtype == bool except AttributeError: return isinstance(x, (bool, np.bool_))