|
23 | 23 | from pandas.core.computation.expressions import (
|
24 | 24 | _NUMEXPR_INSTALLED, _USE_NUMEXPR)
|
25 | 25 | from pandas.core.computation.ops import (
|
26 |
| - _arith_ops_syms, _binary_math_ops, _binary_ops_dict, _bool_ops_syms, |
| 26 | + _arith_ops_syms, _binary_math_ops, _binary_ops_dict, |
27 | 27 | _special_case_arith_ops_syms, _unary_math_ops)
|
28 | 28 | import pandas.util.testing as tm
|
29 | 29 | from pandas.util.testing import (
|
30 | 30 | assert_frame_equal, assert_numpy_array_equal, assert_produces_warning,
|
31 | 31 | assert_series_equal, makeCustomDataframe as mkdf, randbool)
|
32 | 32 |
|
33 |
| -_series_frame_incompatible = _bool_ops_syms |
34 |
| -_scalar_skip = 'in', 'not in' |
35 |
| - |
36 | 33 |
|
37 | 34 | @pytest.fixture(params=(
|
38 | 35 | pytest.param(engine,
|
@@ -162,13 +159,21 @@ def teardown_method(self, method):
|
162 | 159 | del self.pandas_rhses, self.pandas_lhses, self.current_engines
|
163 | 160 |
|
164 | 161 | @pytest.mark.slow
|
165 |
| - def test_complex_cmp_ops(self): |
166 |
| - cmp_ops = ('!=', '==', '<=', '>=', '<', '>') |
167 |
| - cmp2_ops = ('>', '<') |
168 |
| - for lhs, cmp1, rhs, binop, cmp2 in product(self.lhses, cmp_ops, |
169 |
| - self.rhses, self.bin_ops, |
170 |
| - cmp2_ops): |
171 |
| - self.check_complex_cmp_op(lhs, cmp1, rhs, binop, cmp2) |
| 162 | + @pytest.mark.parametrize('cmp1', ['!=', '==', '<=', '>=', '<', '>'], |
| 163 | + ids=['ne', 'eq', 'le', 'ge', 'lt', 'gt']) |
| 164 | + @pytest.mark.parametrize('cmp2', ['>', '<'], ids=['gt', 'lt']) |
| 165 | + def test_complex_cmp_ops(self, cmp1, cmp2): |
| 166 | + for lhs, rhs, binop in product( |
| 167 | + self.lhses, self.rhses, self.bin_ops): |
| 168 | + lhs_new = _eval_single_bin(lhs, cmp1, rhs, self.engine) |
| 169 | + rhs_new = _eval_single_bin(lhs, cmp2, rhs, self.engine) |
| 170 | + expected = _eval_single_bin( |
| 171 | + lhs_new, binop, rhs_new, self.engine) |
| 172 | + |
| 173 | + ex = '(lhs {cmp1} rhs) {binop} (lhs {cmp2} rhs)'.format( |
| 174 | + cmp1=cmp1, binop=binop, cmp2=cmp2) |
| 175 | + result = pd.eval(ex, engine=self.engine, parser=self.parser) |
| 176 | + self.check_equal(result, expected) |
172 | 177 |
|
173 | 178 | def test_simple_cmp_ops(self):
|
174 | 179 | bool_lhses = (DataFrame(randbool(size=(10, 5))),
|
@@ -225,41 +230,6 @@ def check_equal(self, result, expected):
|
225 | 230 | else:
|
226 | 231 | assert result == expected
|
227 | 232 |
|
228 |
| - def check_complex_cmp_op(self, lhs, cmp1, rhs, binop, cmp2): |
229 |
| - skip_these = _scalar_skip |
230 |
| - ex = '(lhs {cmp1} rhs) {binop} (lhs {cmp2} rhs)'.format(cmp1=cmp1, |
231 |
| - binop=binop, |
232 |
| - cmp2=cmp2) |
233 |
| - scalar_with_in_notin = (is_scalar(rhs) and (cmp1 in skip_these or |
234 |
| - cmp2 in skip_these)) |
235 |
| - if scalar_with_in_notin: |
236 |
| - with pytest.raises(TypeError): |
237 |
| - pd.eval(ex, engine=self.engine, parser=self.parser) |
238 |
| - with pytest.raises(TypeError): |
239 |
| - pd.eval(ex, engine=self.engine, parser=self.parser, |
240 |
| - local_dict={'lhs': lhs, 'rhs': rhs}) |
241 |
| - else: |
242 |
| - lhs_new = _eval_single_bin(lhs, cmp1, rhs, self.engine) |
243 |
| - rhs_new = _eval_single_bin(lhs, cmp2, rhs, self.engine) |
244 |
| - if (isinstance(lhs_new, Series) and |
245 |
| - isinstance(rhs_new, DataFrame) and |
246 |
| - binop in _series_frame_incompatible): |
247 |
| - pass |
248 |
| - # TODO: the code below should be added back when left and right |
249 |
| - # hand side bool ops are fixed. |
250 |
| - # |
251 |
| - # try: |
252 |
| - # pytest.raises(Exception, pd.eval, ex, |
253 |
| - # local_dict={'lhs': lhs, 'rhs': rhs}, |
254 |
| - # engine=self.engine, parser=self.parser) |
255 |
| - # except AssertionError: |
256 |
| - # raise |
257 |
| - else: |
258 |
| - expected = _eval_single_bin( |
259 |
| - lhs_new, binop, rhs_new, self.engine) |
260 |
| - result = pd.eval(ex, engine=self.engine, parser=self.parser) |
261 |
| - self.check_equal(result, expected) |
262 |
| - |
263 | 233 | def check_chained_cmp_op(self, lhs, cmp1, mid, cmp2, rhs):
|
264 | 234 |
|
265 | 235 | def check_operands(left, right, cmp_op):
|
|
0 commit comments