Example #1
0
    def test_boolean_ops(self):
        def testit():
            for f, f2 in [(self.frame, self.frame2), (self.mixed, self.mixed2)]:

                f11 = f
                f12 = f + 1

                f21 = f2
                f22 = f2 + 1

                for op, op_str in [("gt", ">"), ("lt", "<"), ("ge", ">="), ("le", "<="), ("eq", "=="), ("ne", "!=")]:

                    op = getattr(operator, op)

                    result = expr._can_use_numexpr(op, op_str, f11, f12, "evaluate")
                    self.assert_(result == (not f11._is_mixed_type))

                    result = expr.evaluate(op, op_str, f11, f12, use_numexpr=True)
                    expected = expr.evaluate(op, op_str, f11, f12, use_numexpr=False)
                    assert_array_equal(result, expected.values)

                    result = expr._can_use_numexpr(op, op_str, f21, f22, "evaluate")
                    self.assert_(result == False)

        expr.set_use_numexpr(False)
        testit()
        expr.set_use_numexpr(True)
        expr.set_numexpr_threads(1)
        testit()
        expr.set_numexpr_threads()
        testit()
Example #2
0
    def test_boolean_ops(self):


        def testit():
            for f, f2 in [ (self.frame, self.frame2), (self.mixed, self.mixed2) ]:

                f11 = f
                f12 = f + 1
            
                f21 = f2
                f22 = f2 + 1

                for op, op_str in [('gt','>'),('lt','<'),('ge','>='),('le','<='),('eq','=='),('ne','!=')]:

                    op = getattr(operator,op)

                    result   = expr._can_use_numexpr(op, op_str, f11, f12, 'evaluate')
                    self.assertTrue(result == (not f11._is_mixed_type))

                    result   = expr.evaluate(op, op_str, f11, f12, use_numexpr=True)
                    expected = expr.evaluate(op, op_str, f11, f12, use_numexpr=False)
                    assert_array_equal(result,expected.values)
                    
                    result   = expr._can_use_numexpr(op, op_str, f21, f22, 'evaluate')
                    self.assertTrue(result == False)

        expr.set_use_numexpr(False)
        testit()
        expr.set_use_numexpr(True)
        expr.set_numexpr_threads(1)
        testit()
        expr.set_numexpr_threads()
        testit()
Example #3
0
    def test_binary_ops(self):
        def testit():

            for f, f2 in [(self.frame, self.frame2), (self.mixed, self.mixed2)]:

                for op, op_str in [("add", "+"), ("sub", "-"), ("mul", "*"), ("div", "/"), ("pow", "**")]:

                    op = getattr(operator, op, None)
                    if op is not None:
                        result = expr._can_use_numexpr(op, op_str, f, f, "evaluate")
                        self.assert_(result == (not f._is_mixed_type))

                        result = expr.evaluate(op, op_str, f, f, use_numexpr=True)
                        expected = expr.evaluate(op, op_str, f, f, use_numexpr=False)
                        assert_array_equal(result, expected.values)

                        result = expr._can_use_numexpr(op, op_str, f2, f2, "evaluate")
                        self.assert_(result == False)

        expr.set_use_numexpr(False)
        testit()
        expr.set_use_numexpr(True)
        expr.set_numexpr_threads(1)
        testit()
        expr.set_numexpr_threads()
        testit()
Example #4
0
    def test_binary_ops(self):

        def testit():

            for f, f2 in [ (self.frame, self.frame2), (self.mixed, self.mixed2) ]:

                for op, op_str in [('add','+'),('sub','-'),('mul','*'),('div','/'),('pow','**')]:

                    op = getattr(operator,op,None)
                    if op is not None:
                        result   = expr._can_use_numexpr(op, op_str, f, f, 'evaluate')
                        self.assertTrue(result == (not f._is_mixed_type))

                        result   = expr.evaluate(op, op_str, f, f, use_numexpr=True)
                        expected = expr.evaluate(op, op_str, f, f, use_numexpr=False)
                        assert_array_equal(result,expected.values)
                
                        result   = expr._can_use_numexpr(op, op_str, f2, f2, 'evaluate')
                        self.assertTrue(result == False)

        
        expr.set_use_numexpr(False)
        testit()
        expr.set_use_numexpr(True)
        expr.set_numexpr_threads(1)
        testit()
        expr.set_numexpr_threads()
        testit()
Example #5
0
    def test_boolean_ops(self):


        def testit():
            for f, f2 in [ (self.frame, self.frame2), (self.mixed, self.mixed2) ]:

                f11 = f
                f12 = f + 1
            
                f21 = f2
                f22 = f2 + 1

                for op, op_str in [('gt','>'),('lt','<'),('ge','>='),('le','<='),('eq','=='),('ne','!=')]:

                    op = getattr(operator,op)

                    result   = expr._can_use_numexpr(op, op_str, f11, f12, 'evaluate')
                    self.assert_(result == (not f11._is_mixed_type))

                    result   = expr.evaluate(op, op_str, f11, f12, use_numexpr=True)
                    expected = expr.evaluate(op, op_str, f11, f12, use_numexpr=False)
                    assert_array_equal(result,expected.values)
                    
                    result   = expr._can_use_numexpr(op, op_str, f21, f22, 'evaluate')
                    self.assert_(result == False)

        expr.set_use_numexpr(False)
        testit()
        expr.set_use_numexpr(True)
        expr.set_numexpr_threads(1)
        testit()
        expr.set_numexpr_threads()
        testit()
Example #6
0
    def test_binary_ops(self):

        def testit():

            for f, f2 in [ (self.frame, self.frame2), (self.mixed, self.mixed2) ]:

                for op, op_str in [('add','+'),('sub','-'),('mul','*'),('div','/'),('pow','**')]:

                    op = getattr(operator,op,None)
                    if op is not None:
                        result   = expr._can_use_numexpr(op, op_str, f, f, 'evaluate')
                        self.assert_(result == (not f._is_mixed_type))

                        result   = expr.evaluate(op, op_str, f, f, use_numexpr=True)
                        expected = expr.evaluate(op, op_str, f, f, use_numexpr=False)
                        assert_array_equal(result,expected.values)
                
                        result   = expr._can_use_numexpr(op, op_str, f2, f2, 'evaluate')
                        self.assert_(result == False)

        
        expr.set_use_numexpr(False)
        testit()
        expr.set_use_numexpr(True)
        expr.set_numexpr_threads(1)
        testit()
        expr.set_numexpr_threads()
        testit()
Example #7
0
    def test_where(self):
        def testit():
            for f in [self.frame, self.frame2, self.mixed, self.mixed2]:

                for cond in [True, False]:

                    c = np.empty(f.shape, dtype=np.bool_)
                    c.fill(cond)
                    result = expr.where(c, f.values, f.values + 1)
                    expected = np.where(c, f.values, f.values + 1)
                    assert_array_equal(result, expected)

        expr.set_use_numexpr(False)
        testit()
        expr.set_use_numexpr(True)
        expr.set_numexpr_threads(1)
        testit()
        expr.set_numexpr_threads()
        testit()
Example #8
0
    def test_where(self):
        def testit():
            for f in [self.frame, self.frame2, self.mixed, self.mixed2]:

                for cond in [True, False]:

                    c = np.empty(f.shape, dtype=np.bool_)
                    c.fill(cond)
                    result = expr.where(c, f.values, f.values + 1)
                    expected = np.where(c, f.values, f.values + 1)
                    assert_array_equal(result, expected)

        expr.set_use_numexpr(False)
        testit()
        expr.set_use_numexpr(True)
        expr.set_numexpr_threads(1)
        testit()
        expr.set_numexpr_threads()
        testit()
Example #9
0
 def run_arithmetic_test(self, df, assert_func, check_dtype=False):
     expr._MIN_ELEMENTS = 0
     operations = ["add", "sub", "mul", "mod", "truediv", "floordiv", "pow"]
     if not py3compat.PY3:
         operations.append("div")
     for arith in operations:
         op = getattr(operator, arith)
         expr.set_use_numexpr(False)
         expected = op(df, df)
         expr.set_use_numexpr(True)
         result = op(df, df)
         try:
             if check_dtype:
                 if arith == "div":
                     assert expected.dtype.kind == df.dtype.kind
                 if arith == "truediv":
                     assert expected.dtype.kind == "f"
             assert_func(expected, result)
         except Exception:
             print("Failed test with operator %r" % op.__name__)
             raise
Example #10
0
 def run_arithmetic_test(self, df, assert_func, check_dtype=False):
     expr._MIN_ELEMENTS = 0
     operations = ['add', 'sub', 'mul','mod','truediv','floordiv','pow']
     if not py3compat.PY3:
         operations.append('div')
     for arith in operations:
         op = getattr(operator, arith)
         expr.set_use_numexpr(False)
         expected = op(df, df)
         expr.set_use_numexpr(True)
         result = op(df, df)
         try:
             if check_dtype:
                 if arith == 'div':
                     assert expected.dtype.kind == df.dtype.kind
                 if arith == 'truediv':
                     assert expected.dtype.kind == 'f'
             assert_func(expected, result)
         except Exception:
             print(("Failed test with operator %r" % op.__name__))
             raise
Example #11
0
 def run_arithmetic_test(self, df, assert_func, check_dtype=False):
     expr._MIN_ELEMENTS = 0
     operations = ['add', 'sub', 'mul','mod','truediv','floordiv','pow']
     if not compat.PY3:
         operations.append('div')
     for arith in operations:
         op = getattr(operator, arith)
         expr.set_use_numexpr(False)
         expected = op(df, df)
         expr.set_use_numexpr(True)
         result = op(df, df)
         try:
             if check_dtype:
                 if arith == 'div':
                     assert expected.dtype.kind == df.dtype.kind
                 if arith == 'truediv':
                     assert expected.dtype.kind == 'f'
             assert_func(expected, result)
         except Exception:
             print("Failed test with operator %r" % op.__name__)
             raise