コード例 #1
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', '**')]:
                    if op == 'div':
                        op = getattr(operator, 'truediv', None)
                    else:
                        op = getattr(operator, op, None)
                    if op is not None:
                        result = expr._can_use_numexpr(op, op_str, f, f,
                                                       'evaluate')
                        self.assertNotEqual(result, 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)
                        tm.assert_numpy_array_equal(result, expected.values)

                        result = expr._can_use_numexpr(op, op_str, f2, f2,
                                                       'evaluate')
                        self.assertFalse(result)

        expr.set_use_numexpr(False)
        testit()
        expr.set_use_numexpr(True)
        expr.set_numexpr_threads(1)
        testit()
        expr.set_numexpr_threads()
        testit()
コード例 #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.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()
コード例 #3
0
ファイル: test_expressions.py プロジェクト: agijsberts/pandas
    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.assertNotEqual(result, 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)
                    tm.assert_numpy_array_equal(result,expected.values)

                    result   = expr._can_use_numexpr(op, op_str, f21, f22, 'evaluate')
                    self.assertFalse(result)

        expr.set_use_numexpr(False)
        testit()
        expr.set_use_numexpr(True)
        expr.set_numexpr_threads(1)
        testit()
        expr.set_numexpr_threads()
        testit()
コード例 #4
0
    def setup(self, use_numexpr, threads):
        self.df = DataFrame(np.random.randn(20000, 100))
        self.df2 = DataFrame(np.random.randn(20000, 100))

        if threads != 'default':
            expr.set_numexpr_threads(threads)
        if not use_numexpr:
            expr.set_use_numexpr(False)
コード例 #5
0
ファイル: eval.py プロジェクト: ChristopherShort/pandas
    def setup(self, engine, threads):
        self.df = DataFrame(np.random.randn(20000, 100))
        self.df2 = DataFrame(np.random.randn(20000, 100))
        self.df3 = DataFrame(np.random.randn(20000, 100))
        self.df4 = DataFrame(np.random.randn(20000, 100))

        if threads == 1:
            expr.set_numexpr_threads(1)
コード例 #6
0
    def setup(self, engine, threads):
        self.df = DataFrame(np.random.randn(20000, 100))
        self.df2 = DataFrame(np.random.randn(20000, 100))
        self.df3 = DataFrame(np.random.randn(20000, 100))
        self.df4 = DataFrame(np.random.randn(20000, 100))

        if threads == 1:
            expr.set_numexpr_threads(1)
コード例 #7
0
ファイル: test_expressions.py プロジェクト: youngyan99/pandas
    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', '**')]:

                    # numpy >= 1.11 doesn't handle integers
                    # raised to integer powers
                    # https://github.com/pandas-dev/pandas/issues/15363
                    if op == 'pow' and not _np_version_under1p11:
                        continue

                    if op == 'div':
                        op = getattr(operator, 'truediv', None)
                    else:
                        op = getattr(operator, op, None)
                    if op is not None:
                        result = expr._can_use_numexpr(op, op_str, f, f,
                                                       'evaluate')
                        self.assertNotEqual(result, 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)

                        if isinstance(result, DataFrame):
                            tm.assert_frame_equal(result, expected)
                        else:
                            tm.assert_numpy_array_equal(
                                result, expected.values)

                        result = expr._can_use_numexpr(op, op_str, f2, f2,
                                                       'evaluate')
                        self.assertFalse(result)

        expr.set_use_numexpr(False)
        testit()
        expr.set_use_numexpr(True)
        expr.set_numexpr_threads(1)
        testit()
        expr.set_numexpr_threads()
        testit()
コード例 #8
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', '**')]:

                    # numpy >= 1.11 doesn't handle integers
                    # raised to integer powers
                    # https://github.com/pandas-dev/pandas/issues/15363
                    if op == 'pow' and not _np_version_under1p11:
                        continue

                    if op == 'div':
                        op = getattr(operator, 'truediv', None)
                    else:
                        op = getattr(operator, op, None)
                    if op is not None:
                        result = expr._can_use_numexpr(op, op_str, f, f,
                                                       'evaluate')
                        self.assertNotEqual(result, 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)

                        if isinstance(result, DataFrame):
                            tm.assert_frame_equal(result, expected)
                        else:
                            tm.assert_numpy_array_equal(result,
                                                        expected.values)

                        result = expr._can_use_numexpr(op, op_str, f2, f2,
                                                       'evaluate')
                        self.assertFalse(result)

        expr.set_use_numexpr(False)
        testit()
        expr.set_use_numexpr(True)
        expr.set_numexpr_threads(1)
        testit()
        expr.set_numexpr_threads()
        testit()
コード例 #9
0
ファイル: test_expressions.py プロジェクト: BRGM/Pic-EAU
    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)
                    tm.assert_numpy_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()
コード例 #10
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)
                    tm.assert_numpy_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()
コード例 #11
0
ファイル: indexing.py プロジェクト: Alias4bb/pandas
 def setup(self):
     if (expr is None):
         raise NotImplementedError
     self.df = DataFrame(np.random.randn(50000, 100))
     self.df2 = DataFrame(np.random.randn(50000, 100))
     expr.set_numexpr_threads(1)
コード例 #12
0
 def teardown(self, engine, threads):
     expr.set_numexpr_threads()
コード例 #13
0
ファイル: indexing.py プロジェクト: scarrucciu/pandas
 def setup(self):
     self.df = DataFrame(np.random.randn(50000, 100))
     self.df2 = DataFrame(np.random.randn(50000, 100))
     expr.set_numexpr_threads(1)
コード例 #14
0
ファイル: indexing.py プロジェクト: scarrucciu/pandas
 def teardown(self):
     expr.set_numexpr_threads()
コード例 #15
0
 def teardown(self):
     expr.set_numexpr_threads()
コード例 #16
0
 def setup(self):
     self.df = DataFrame(np.random.randn(20000, 100))
     self.df2 = DataFrame(np.random.randn(20000, 100))
     expr.set_numexpr_threads(1)
コード例 #17
0
 def teardown(self, use_numexpr, threads):
     expr.set_use_numexpr(True)
     expr.set_numexpr_threads()
コード例 #18
0
 def setup(self):
     if (expr is None):
         raise NotImplementedError
     self.df = DataFrame(np.random.randn(50000, 100))
     self.df2 = DataFrame(np.random.randn(50000, 100))
     expr.set_numexpr_threads(1)
コード例 #19
0
ファイル: eval.py プロジェクト: AlexisMignon/pandas
 def teardown(self, engine, threads):
     expr.set_numexpr_threads()