I’ve just released [boost-histogram 1.7][] and [hist 2.10][], with a major new feature and a big typing improvement! I’d like to quickly outline what’s new here. Python 3.10+ is now required.
The MultiCell storage
The biggest new feature is the MultiCell storage, our first new storage, which
allows you to store a present number of weights into a single histogram. Here’s
how it works:
from hist import Hist
h = Hist.new.Regular(10, 0, 20).MultiCell(3)
Here you can see we are using Hist’s QuickConstruct syntax, which supports the
new MultiCell storage type. We made a histogram with 10 regularly spaced bins
from 0 to 20, and each bin contains 3 values. Now when we fill, we pass in these
values as weights:
>>> h.fill(1, weight=[[1, 2, 3]])
Hist(Regular(10, 0, 20, label='Axis 0'), storage=MultiCell(3)) # Sum: [1.0, 2.0, 3.0]
You can already see this working in the repr. The sum shows three values instead of the usual one.
>>> h.sum()
[1.0, 2.0, 3.0]
You can select a value from the histogram, and all three values are returned:
>>> h[0]
[1.0, 2.0, 3.0]
Similarly, you can access all the values:
>>> h.values()
array([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[2., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[3., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])
Static typing
A huge change in static typing was implemented: histograms are now Generic; the
storage is now part of the Hist/Histogram type. This means that the type of the
histogram h here:
h = Hist.new.Integer(0, 10).Double()
h is now Hist[Double]. The various methods that return things that depend on
this type now have a more restricted set of returns if they know this type, for
example:
h = Hist.new.Boolean().Weight()
s = h.sum()
print(f"{s.value=} {s.variance=}")
is well typed; the type system knows that sum returns a WeightedSum
accumulator instead of a simple value. Before, you’d have had to fill your code
with asserts to enforce the correct type via narrowing. Now it works for you.
If you are implementing functions with histogram types, keep in mind that you’ll
now want to replace Hist with Hist[Any] if you have full strictness enabled
in your type checker.
This enabled us to turn on type checking for our examples (since before it would have required adding asserts and/or type ignores). We found a few areas where we could improve the return types, as well.
Other things
We now require Python 3.10+; we used this to simplify our logic with pattern matching. We also removed support for the experimental CPython 3.13t; if you are using free-threading, please update to CPython 3.14t, which is not experimental.
We now record and respect the growth status in serialization.
Hope you enjoy this new release!