def test_multiply_by_scalar_inplace(self): lj_series = lj.Series.arange(0, 5) lj_series *= 2 self.assertEqual(lj_series.sum(), 20) # Speed Test run_series_method_tests('series *= 2')
def test_multiply_by_scalar(self): lj_series = lj.Series.arange(0, 5) result = lj_series * 2 self.assertEqual(result.sum(), 20) # Speed Test run_series_method_tests('series * 2')
def test_add_by_scalar_inplace(self): lj_series = lj.Series.arange(0, 5) lj_series += 1 self.assertEqual(lj_series.sum(), 15) # Speed Test run_series_method_tests('series += 1')
def test_add_by_scalar(self): lj_series = lj.Series.arange(0, 5) result = lj_series + 1 self.assertEqual(result.sum(), 15) # Speed Test run_series_method_tests('series + 1')
def test_series_map(self): lj_series = lj.Series.arange(0, 10, float) variable = 2.0 self.assertNotEqual(lj_series.sum(), 0.0) #result = lj_series.map(lambda v: v * 0.0, out_dtype=float) #self.assertEqual(result.sum(), 0.0) #logger.debug('Result values: {}'.format(result.to_numpy().astype(int))) #result1 = lj_series.map(lambda v: 2.0, out_dtype=float) #result2 = lj_series.map(lambda v: 30, out_dtype=float) #logger.debug('Result from .map() -> {}'.format(result)) lj_time, pd_time, _ = run_series_method_tests( stmt="series.map(lambda v: v)", skip_numpy=True, n_iter=20)
def test_mean(self): """ Test average/mean of series """ lj_series = lj.Series.arange(0, 10000) pd_series = pd.Series(np.arange(0, 10000)) avg = lj_series.mean() logger.debug('Mean of arange(0, 10000) -> {:.4f}'.format(avg)) self.assertEqual(lj_series.mean(), pd_series.mean()) # Speed test lj_time, pd_time, np_time = run_series_method_tests('series.mean()') self.assertLessEqual(lj_time, pd_time)
def test_sum(self): """ Test the ability to sum a series """ series = lj.Series.arange(0, 4) total = series.sum() logger.debug('Sum of arange(0, 4) is: {}'.format(total)) self.assertEqual(total, 6) # Speed test lj_time, pd_time, np_time = run_series_method_tests('series.sum()') self.assertLessEqual( lj_time, np_time, msg='Expected LumberJack .sum() to be faster but it was not!')
def test_cumsum(self): """ Test cumulative sum of series """ series = lj.Series.arange(0, 4) _pd_series = pd.Series(np.arange(0, 4)) cumsum = series.cumsum() logger.debug('Got cumsum of {}'.format(cumsum)) # Ensure they sum to the same lj_cumsum_sum = series.cumsum().sum() pd_cumsum_sum = _pd_series.cumsum().sum() self.assertEqual( lj_cumsum_sum, pd_cumsum_sum, msg= 'LumberJack and Pandas .cumsum().sum() does not match! -- LumberJack: {}, Pandas: {}' .format(lj_cumsum_sum, pd_cumsum_sum)) # Speed test lj_time, pd_time, np_time = run_series_method_tests('series.cumsum()') self.assertLessEqual(lj_time, pd_time)