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()
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()
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()
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)
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)
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()
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()
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()
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)
def teardown(self, engine, threads): expr.set_numexpr_threads()
def setup(self): self.df = DataFrame(np.random.randn(50000, 100)) self.df2 = DataFrame(np.random.randn(50000, 100)) expr.set_numexpr_threads(1)
def teardown(self): expr.set_numexpr_threads()
def setup(self): self.df = DataFrame(np.random.randn(20000, 100)) self.df2 = DataFrame(np.random.randn(20000, 100)) expr.set_numexpr_threads(1)
def teardown(self, use_numexpr, threads): expr.set_use_numexpr(True) expr.set_numexpr_threads()