diff --git a/packages/boost-histogram/meta.yaml b/packages/boost-histogram/meta.yaml new file mode 100644 index 00000000000..7c85048e048 --- /dev/null +++ b/packages/boost-histogram/meta.yaml @@ -0,0 +1,20 @@ +package: + name: boost-histogram + version: 1.3.0 +source: + url: https://files.pythonhosted.org/packages/0a/9a/1ebde600886eee433a99434e0ddb462630a0b25ab1f58efb91ffc385a0ff/boost_histogram-1.3.0.tar.gz + sha256: 62240dae889cbf05f8b4f2203f0b7d6c7a2e029502723a377fc33226e425ce50 +requirements: + run: + - numpy +build: + script: | + pip install setuptools_scm[toml] +test: + imports: + - boost-histogram +about: + home: https://github.com/scikit-hep/boost-histogram + PyPI: https://pypi.org/project/boost-histogram + summary: The Boost::Histogram Python wrapper. + license: BSD-3-Clause diff --git a/packages/boost-histogram/test_boost_histogram.py b/packages/boost-histogram/test_boost_histogram.py new file mode 100644 index 00000000000..ed30cf40a31 --- /dev/null +++ b/packages/boost-histogram/test_boost_histogram.py @@ -0,0 +1,42 @@ +from pyodide_build.testing import run_in_pyodide + + +@run_in_pyodide(packages=["boost-histogram"]) +def test_boost_histogram(): + import boost_histogram as bh + import unittest + + class TestBasicHistogram(unittest.TestCase): + + def test_1d_histogram(self): + h = bh.Histogram(bh.axis.Integer(0, 10)) + h.fill([1,1,1,14]) + self.assertEquals(h[bh.underflow], 0) + self.assertEquals(h[bh.loc(0)], 0) + self.assertEquals(h[bh.loc(1)], 3) + self.assertEquals(h[bh.overflow], 1) + + self.assertEquals(h.sum(), 3) + self.assertEquals(h.sum(flow=True), 4) + self.assertEquals(h[sum], 4) + + def test_2d_histogram(self): + h = bh.Histogram(bh.axis.Regular(10,0,10), bh.axes.Boolean()) + self.assertEquals(len(h.axes[0]), 10) + self.assertEquals(len(h.axes[0]), 2) + + h.fill([.5, .5, 3.5], [True, False, True]) + self.assertEquals(h[sum, bh.loc(True)], 2) + self.assertEquals(h[sum, bh.loc(False)], 1) + self.assertEquals(h[0, sum], 2) + self.assertEquals(h[0, bh.loc(True)], 1) + + def test_cat_histogram(self): + h = bh.Histogram(bh.axis.StrCategory(growth=True)) + h.fill("fear leads to anger anger leads to hate hate leads to suffering".split()) + + self.assertEquals(h[bh.loc("fear")], 1) + self.assertEquals(h[bh.loc("anger")], 2) + self.assertEquals(h[bh.loc("hate")], 2) + self.assertEquals(h[bh.loc("to")], 3) +