def test_from_array(named_hist): h = Hist( axis.Regular(10, 1, 2, name="A"), axis.Regular(7, 1, 3, name="B"), data=np.ones((10, 7)), ) assert h.values() == approx(np.ones((10, 7))) assert h.sum() == approx(70) assert h.sum(flow=True) == approx(70) h = Hist( axis.Regular(10, 1, 2, name="A"), axis.Regular(7, 1, 3, name="B"), data=np.ones((12, 9)), ) assert h.values(flow=False) == approx(np.ones((10, 7))) assert h.values(flow=True) == approx(np.ones((12, 9))) assert h.sum() == approx(70) assert h.sum(flow=True) == approx(12 * 9) with pytest.raises(ValueError): h = Hist( axis.Regular(10, 1, 2, name="A"), axis.Regular(7, 1, 3, name="B"), data=np.ones((11, 9)), )
def test_sum_empty_axis_hist(): h = Hist( axis.StrCategory("", growth=True), axis.Regular(10, 0, 1), storage=storage.Weight(), ) assert h.sum().value == 0 assert "Str" in repr(h) h._repr_html_()