diff --git a/pandas/computation/tests/test_eval.py b/pandas/computation/tests/test_eval.py index 4dc1e24618a83..5019dd392a567 100644 --- a/pandas/computation/tests/test_eval.py +++ b/pandas/computation/tests/test_eval.py @@ -248,7 +248,8 @@ def check_operands(left, right, cmp_op): for ex in (ex1, ex2, ex3): result = pd.eval(ex, engine=self.engine, parser=self.parser) - tm.assert_numpy_array_equal(result, expected) + + tm.assert_almost_equal(result, expected) def check_simple_cmp_op(self, lhs, cmp1, rhs): ex = 'lhs {0} rhs'.format(cmp1) @@ -265,7 +266,8 @@ def check_binary_arith_op(self, lhs, arith1, rhs): ex = 'lhs {0} rhs'.format(arith1) result = pd.eval(ex, engine=self.engine, parser=self.parser) expected = _eval_single_bin(lhs, arith1, rhs, self.engine) - tm.assert_numpy_array_equal(result, expected) + + tm.assert_almost_equal(result, expected) ex = 'lhs {0} rhs {0} rhs'.format(arith1) result = pd.eval(ex, engine=self.engine, parser=self.parser) nlhs = _eval_single_bin(lhs, arith1, rhs, @@ -280,8 +282,10 @@ def check_alignment(self, result, nlhs, ghs, op): # TypeError, AttributeError: series or frame with scalar align pass else: + + # direct numpy comparison expected = self.ne.evaluate('nlhs {0} ghs'.format(op)) - tm.assert_numpy_array_equal(result, expected) + tm.assert_numpy_array_equal(result.values, expected) # modulus, pow, and floor division require special casing @@ -349,12 +353,12 @@ def check_single_invert_op(self, lhs, cmp1, rhs): elb = np.array([bool(el)]) expected = ~elb result = pd.eval('~elb', engine=self.engine, parser=self.parser) - tm.assert_numpy_array_equal(expected, result) + tm.assert_almost_equal(expected, result) for engine in self.current_engines: tm.skip_if_no_ne(engine) - tm.assert_numpy_array_equal(result, pd.eval('~elb', engine=engine, - parser=self.parser)) + tm.assert_almost_equal(result, pd.eval('~elb', engine=engine, + parser=self.parser)) def check_compound_invert_op(self, lhs, cmp1, rhs): skip_these = 'in', 'not in' @@ -374,13 +378,13 @@ def check_compound_invert_op(self, lhs, cmp1, rhs): else: expected = ~expected result = pd.eval(ex, engine=self.engine, parser=self.parser) - tm.assert_numpy_array_equal(expected, result) + tm.assert_almost_equal(expected, result) # make sure the other engines work the same as this one for engine in self.current_engines: tm.skip_if_no_ne(engine) ev = pd.eval(ex, engine=self.engine, parser=self.parser) - tm.assert_numpy_array_equal(ev, result) + tm.assert_almost_equal(ev, result) def ex(self, op, var_name='lhs'): return '{0}{1}'.format(op, var_name) @@ -728,7 +732,7 @@ def check_alignment(self, result, nlhs, ghs, op): pass else: expected = eval('nlhs {0} ghs'.format(op)) - tm.assert_numpy_array_equal(result, expected) + tm.assert_almost_equal(result, expected) class TestEvalPythonPandas(TestEvalPythonPython): diff --git a/pandas/util/testing.py b/pandas/util/testing.py index ef94692ea9673..03ccfcab24f58 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -25,7 +25,8 @@ import pandas as pd from pandas.core.common import (is_sequence, array_equivalent, is_list_like, is_datetimelike_v_numeric, - is_datetimelike_v_object, is_number, + is_datetimelike_v_object, + is_number, is_bool, needs_i8_conversion, is_categorical_dtype) from pandas.formats.printing import pprint_thing from pandas.core.algorithms import take_1d @@ -157,6 +158,9 @@ def assert_almost_equal(left, right, check_exact=False, if is_number(left) and is_number(right): # do not compare numeric classes, like np.float64 and float pass + elif is_bool(left) and is_bool(right): + # do not compare bool classes, like np.bool_ and bool + pass else: if (isinstance(left, np.ndarray) or isinstance(right, np.ndarray)):