def test_merge():
    s = SummaryStats()
    half = int(len(normal) / 2)
    s.update(normal[:half])
    s2 = SummaryStats()
    s2.update(normal[half:])
    sol = SummaryStats()
    sol.update(normal)

    s.merge(s2)
    np.testing.assert_allclose(s.count(), sol.count(), rtol=RTOL, atol=ATOL)
    np.testing.assert_allclose(s.sum(), sol.sum(), rtol=RTOL, atol=ATOL)
    np.testing.assert_allclose(s.min(), sol.min(), rtol=RTOL, atol=ATOL)
    np.testing.assert_allclose(s.max(), sol.max(), rtol=RTOL, atol=ATOL)
    np.testing.assert_allclose(s.var(), sol.var(), rtol=RTOL, atol=ATOL)
    np.testing.assert_allclose(s.skew(), sol.skew(), rtol=RTOL, atol=ATOL)
    np.testing.assert_allclose(s.kurt(), sol.kurt(), rtol=RTOL, atol=ATOL)

    # Test merge both ways is idempotent
    empty_with_full = SummaryStats()
    empty_with_full.merge(sol)
    full_with_empty = copy(sol)
    full_with_empty.merge(SummaryStats())

    for s in [empty_with_full, full_with_empty]:
        np.testing.assert_equal(s.count(), sol.count())
        np.testing.assert_equal(s.sum(), sol.sum())
        np.testing.assert_equal(s.min(), sol.min())
        np.testing.assert_equal(s.max(), sol.max())
        np.testing.assert_equal(s.var(), sol.var())
        np.testing.assert_equal(s.skew(), sol.skew())
        np.testing.assert_equal(s.kurt(), sol.kurt())
def test_pickle(x):
    s = SummaryStats()
    s.update(x)
    s2 = pickle.loads(pickle.dumps(s, protocol=2))
    np.testing.assert_equal(s.count(), s2.count())
    np.testing.assert_equal(s.sum(), s2.sum())
    np.testing.assert_equal(s.min(), s2.min())
    np.testing.assert_equal(s.max(), s2.max())
    np.testing.assert_equal(s.var(), s2.var())
    np.testing.assert_equal(s.skew(), s2.skew())
    np.testing.assert_equal(s.kurt(), s2.kurt())
def test_kurt(x, bias, fisher):
    stats = pytest.importorskip('scipy.stats')
    s = SummaryStats()
    s.update(x)

    res = s.kurt(bias=bias, fisher=fisher)
    if len(x):
        sol = stats.kurtosis(x[~np.isnan(x)], bias=bias, fisher=fisher)
    else:
        sol = np.nan
    np.testing.assert_allclose(res, sol, rtol=RTOL, atol=ATOL)