# Check the statistic has a working __str__ and name method assert isinstance(str(stat), str) if isinstance(stat, stats.Univariate): assert isinstance(stat.name, str) @pytest.mark.parametrize( 'stat, func', [(stats.Kurtosis(bias=True), sp_stats.kurtosis), (stats.Kurtosis(bias=False), functools.partial(sp_stats.kurtosis, bias=False)), (stats.Mean(), statistics.mean), (stats.Skew(bias=True), sp_stats.skew), (stats.Skew(bias=False), functools.partial(sp_stats.skew, bias=False)), (stats.Var(ddof=0), np.var), (stats.Var(), functools.partial(np.var, ddof=1))]) def test_univariate(stat, func): # Shut up np.warnings.filterwarnings('ignore') X = [random.random() for _ in range(30)] for i, x in enumerate(X): stat.update(x) try: assert math.isclose(stat.get(), func(X[:i + 1]), abs_tol=1e-10) except AssertionError: # Errors for the first value are acceptable if i == 0:
def __init__(self, seed=None): super().__init__() self.variance = stats.Var() self.mean = stats.Mean() self.seed = seed self._rng = random.Random(seed)