def test_std(): (chunk, chunk_expr), (agg, agg_expr) = split(t, t.amount.std()) assert chunk.schema == t.schema assert chunk_expr.isidentical(summary(x=chunk.amount.sum(), x2=(chunk.amount ** 2).sum(), n=chunk.amount.count(), keepdims=True)) assert isrecord(agg.dshape.measure) assert agg_expr.isidentical(sqrt((agg.x2.sum() / (agg.n.sum()) - (agg.x.sum() / (agg.n.sum())) ** 2)))
def test_std(): (chunk, chunk_expr), (agg, agg_expr) = split(t, t.amount.std()) assert chunk.schema == t.schema assert chunk_expr.isidentical( summary(x=chunk.amount.sum(), x2=(chunk.amount**2).sum(), n=chunk.amount.count(), keepdims=True)) assert isrecord(agg.dshape.measure) assert agg_expr.isidentical( sqrt(agg.x2.sum() / agg.n.sum() - (agg.x.sum() / (agg.n.sum()))**2))
def test_complex_summaries(): t = symbol('t', '100 * {a: int, b: int}') (chunk, chunk_expr), (agg, agg_expr) = split( t, summary(q=t.a.mean(), w=t.a.std(), e=t.a.sum())) assert chunk_expr.isidentical( summary(e=chunk.a.sum(), q_count=chunk.a.count(), q_total=chunk.a.sum(), w_n=chunk.a.count(), w_x=chunk.a.sum(), w_x2=(chunk.a**2).sum(), keepdims=True)) expected = summary(e=agg.e.sum(), q=agg.q_total.sum() / agg.q_count.sum(), w=sqrt((agg.w_x2.sum() / agg.w_n.sum()) - (agg.w_x.sum() / agg.w_n.sum())**2)) assert agg_expr.isidentical(expected)
def test_complex_summaries(): t = symbol('t', '100 * {a: int, b: int}') (chunk, chunk_expr), (agg, agg_expr) = split(t, summary(q=t.a.mean(), w=t.a.std(), e=t.a.sum())) assert chunk_expr.isidentical(summary(e=chunk.a.sum(), q_count=chunk.a.count(), q_total=chunk.a.sum(), w_n=chunk.a.count(), w_x=chunk.a.sum(), w_x2=(chunk.a ** 2).sum(), keepdims=True)) expected = summary(e=agg.e.sum(), q=agg.q_total.sum() / agg.q_count.sum(), w=sqrt((agg.w_x2.sum() / agg.w_n.sum()) - (agg.w_x.sum() / agg.w_n.sum()) ** 2)) assert agg_expr.isidentical(expected)