Skip to content

TST: computation/test_eval.py tests (slow) #13339

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
22 changes: 13 additions & 9 deletions pandas/computation/tests/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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'
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 5 additions & 1 deletion pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)):
Expand Down