Skip to content

Commit b2ee5e8

Browse files
committed
TST: computation/test_eval.py tests (slow)
closes #13338
1 parent 8bbd2bc commit b2ee5e8

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

pandas/computation/tests/test_eval.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ def check_operands(left, right, cmp_op):
248248
for ex in (ex1, ex2, ex3):
249249
result = pd.eval(ex, engine=self.engine,
250250
parser=self.parser)
251-
tm.assert_numpy_array_equal(result, expected)
251+
252+
tm.assert_almost_equal(result, expected)
252253

253254
def check_simple_cmp_op(self, lhs, cmp1, rhs):
254255
ex = 'lhs {0} rhs'.format(cmp1)
@@ -265,7 +266,8 @@ def check_binary_arith_op(self, lhs, arith1, rhs):
265266
ex = 'lhs {0} rhs'.format(arith1)
266267
result = pd.eval(ex, engine=self.engine, parser=self.parser)
267268
expected = _eval_single_bin(lhs, arith1, rhs, self.engine)
268-
tm.assert_numpy_array_equal(result, expected)
269+
270+
tm.assert_almost_equal(result, expected)
269271
ex = 'lhs {0} rhs {0} rhs'.format(arith1)
270272
result = pd.eval(ex, engine=self.engine, parser=self.parser)
271273
nlhs = _eval_single_bin(lhs, arith1, rhs,
@@ -280,8 +282,10 @@ def check_alignment(self, result, nlhs, ghs, op):
280282
# TypeError, AttributeError: series or frame with scalar align
281283
pass
282284
else:
285+
286+
# direct numpy comparison
283287
expected = self.ne.evaluate('nlhs {0} ghs'.format(op))
284-
tm.assert_numpy_array_equal(result, expected)
288+
tm.assert_numpy_array_equal(result.values, expected)
285289

286290
# modulus, pow, and floor division require special casing
287291

@@ -349,12 +353,12 @@ def check_single_invert_op(self, lhs, cmp1, rhs):
349353
elb = np.array([bool(el)])
350354
expected = ~elb
351355
result = pd.eval('~elb', engine=self.engine, parser=self.parser)
352-
tm.assert_numpy_array_equal(expected, result)
356+
tm.assert_almost_equal(expected, result)
353357

354358
for engine in self.current_engines:
355359
tm.skip_if_no_ne(engine)
356-
tm.assert_numpy_array_equal(result, pd.eval('~elb', engine=engine,
357-
parser=self.parser))
360+
tm.assert_almost_equal(result, pd.eval('~elb', engine=engine,
361+
parser=self.parser))
358362

359363
def check_compound_invert_op(self, lhs, cmp1, rhs):
360364
skip_these = 'in', 'not in'
@@ -374,13 +378,13 @@ def check_compound_invert_op(self, lhs, cmp1, rhs):
374378
else:
375379
expected = ~expected
376380
result = pd.eval(ex, engine=self.engine, parser=self.parser)
377-
tm.assert_numpy_array_equal(expected, result)
381+
tm.assert_almost_equal(expected, result)
378382

379383
# make sure the other engines work the same as this one
380384
for engine in self.current_engines:
381385
tm.skip_if_no_ne(engine)
382386
ev = pd.eval(ex, engine=self.engine, parser=self.parser)
383-
tm.assert_numpy_array_equal(ev, result)
387+
tm.assert_almost_equal(ev, result)
384388

385389
def ex(self, op, var_name='lhs'):
386390
return '{0}{1}'.format(op, var_name)
@@ -728,7 +732,7 @@ def check_alignment(self, result, nlhs, ghs, op):
728732
pass
729733
else:
730734
expected = eval('nlhs {0} ghs'.format(op))
731-
tm.assert_numpy_array_equal(result, expected)
735+
tm.assert_almost_equal(result, expected)
732736

733737

734738
class TestEvalPythonPandas(TestEvalPythonPython):

pandas/util/testing.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
import pandas as pd
2626
from pandas.core.common import (is_sequence, array_equivalent,
2727
is_list_like, is_datetimelike_v_numeric,
28-
is_datetimelike_v_object, is_number,
28+
is_datetimelike_v_object,
29+
is_number, is_bool,
2930
needs_i8_conversion, is_categorical_dtype)
3031
from pandas.formats.printing import pprint_thing
3132
from pandas.core.algorithms import take_1d
@@ -157,6 +158,9 @@ def assert_almost_equal(left, right, check_exact=False,
157158
if is_number(left) and is_number(right):
158159
# do not compare numeric classes, like np.float64 and float
159160
pass
161+
elif is_bool(left) and is_bool(right):
162+
# do not compare bool classes, like np.bool_ and bool
163+
pass
160164
else:
161165
if (isinstance(left, np.ndarray) or
162166
isinstance(right, np.ndarray)):

0 commit comments

Comments
 (0)