def test_statistics(self): self.assertDictEqual( bc.helper.group.statistics(self.random_int_list, summary='default'), { 'mean': mean(self.random_int_list, winsorize=False), 'std': std(self.random_int_list, winsorize=False), }) def mean_std(key): return { 'mean': mean([getattr(s, key) for s in self.sum_stats_list], winsorize=False), 'std': std([getattr(s, key) for s in self.sum_stats_list], winsorize=False), } self.assertDictEqual( bc.helper.group.statistics(self.sum_stats_list, summary='extended'), { 'kurtosis': mean_std('kurtosis'), 'mean': mean_std('mean'), 'median': mean_std('median'), 'skewness': mean_std('skewness'), 'std': mean_std('std'), 'min': mean_std('min'), 'max': mean_std('max') }) self.assertEqual(bc.helper.group.statistics([]).values(), [None] * 2)
def _default_stats(agg): if agg is None or len(agg) == 0: return {'mean': None, 'std': None} else: # Some functions may return None values # It's better to filter them agg = filter(lambda x: x is not None, agg) return {'mean': mean(agg), 'std': std(agg)}
def mean_std(key): return { 'mean': mean([getattr(s, key) for s in self.sum_stats_list], winsorize=False), 'std': std([getattr(s, key) for s in self.sum_stats_list], winsorize=False), }
def test_statistics(self): self.assertDictEqual(bc.helper.group.statistics(self.random_int_list, summary='default'), { 'mean': mean(self.random_int_list), 'std': std(self.random_int_list), }) def mean_std(key): return { 'mean': mean([getattr(s, key) for s in self.sum_stats_list]), 'std': std([getattr(s, key) for s in self.sum_stats_list]), } self.assertDictEqual(bc.helper.group.statistics(self.sum_stats_list, summary='extended'), { 'kurtosis': mean_std('kurtosis'), 'mean': mean_std('mean'), 'median': mean_std('median'), 'skewness': mean_std('skewness'), 'std': mean_std('std'), 'min': mean_std('min'), 'max': mean_std('max') }) self.assertEqual(bc.helper.group.statistics([]).values(), [None] * 2)
def mean_std(key): return { 'mean': mean([getattr(s, key) for s in self.sum_stats_list]), 'std': std([getattr(s, key) for s in self.sum_stats_list]), }