Skip to content

Commit

Permalink
Add boost-histogram
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Feb 14, 2022
1 parent f784e5e commit e9e6a09
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 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
42 changes: 42 additions & 0 deletions 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)

0 comments on commit e9e6a09

Please sign in to comment.