Registry / data / boost-histogram

boost-histogram

JSON →
library1.8.0pypypi✓ verified 25d ago

Boost-histogram is a high-performance Python library providing bindings for the C++14 Boost.Histogram library, designed for fast, multi-dimensional generalized histogramming. It treats histograms as first-class objects, enabling easy filling, manipulation, slicing, and projection. The library is currently at version 1.7.2 and maintains an active release cadence with frequent updates and new features, often driven by the Scikit-HEP project.

pip install boost-histogram
INSTALL
IMPORT
SIG · BOOST-HISTOGRAM
B
boost-histogram
datapythonv1.8.0
Install
4.0s avg
Import
288ms
Disk
96MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.8.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.280s · 98.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.0s · import 0.296s · 91MB
96MB installed
● package 96MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

boost_histogram
import boost_histogram as bh
Histogram
bh.Histogram(...)
from boost_histogram import Histogram
The common pattern is to import `boost_histogram` as `bh` and then access `Histogram` and axis types through `bh.Histogram` and `bh.axis.*`.
axis.Regular
bh.axis.Regular(...)

This quickstart demonstrates how to create a 1D histogram using a regular axis, fill it with random data, and then access its bin counts and axis centers.

import boost_histogram as bh import numpy as np # Create a 1D histogram with 10 bins from 0 to 1 hist = bh.Histogram(bh.axis.Regular(10, 0, 1)) # Fill the histogram with data data = np.random.rand(1000) hist.fill(data) # Access histogram values (counts) counts = hist.view() print(f"Histogram counts: {counts[:5]}...") # Access axis centers centers = hist.axes[0].centers print(f"Axis centers: {centers[:5]}...")
Debug
Known issues
breakingPython version support has significantly changed across recent versions. Python 3.7 support was removed in `1.5.0`, Python 3.8 support was dropped after `1.5.2` (meaning `1.6.0` and later do not support 3.8), and Python 3.10+ is now required as of `1.7.0`.
fix
Ensure your Python environment is 3.10 or newer when using `boost-histogram` version `1.7.0` or later. For older `boost-histogram` versions, check the specific Python requirements.
affects: >=1.5.0, >=1.6.0, >=1.7.0
deprecatedThe internal `_storage_type` attribute changed from a `PendingDeprecationWarning` to a full `DeprecationWarning`.
fix
Avoid direct reliance on `_storage_type` and use documented API for storage interaction if available, or upgrade to a more recent version and check alternatives if this was for advanced use cases.
affects: >=1.4.0
gotchaFilling integer-based axes with floating-point arrays (or single floats) is now explicitly disallowed to prevent rounding issues around 0.
fix
When filling axes designed for integers (e.g., `bh.axis.Integer`), ensure your input data are actual integers or integer-like values, not floats. Cast floats to integers explicitly if needed.
affects: >=1.4.0
breakingSerialization behavior and format have seen several fixes and changes across versions, particularly around metadata and complex storages. This could lead to issues when loading histograms saved with older versions or in different environments.
fix
Ensure that the `boost-histogram` version used for saving and loading histograms is consistent. If upgrading, re-save any critical histograms after the upgrade, or verify compatibility with the `uhi` library for unified serialization.
affects: >=1.6.0, >=1.6.1
gotchaWith the introduction of `MultiCell` storage and generic histogram types, advanced type checking might require updating type hints. Histograms are now generic, meaning `Hist` may need to be `Hist[Any]` in strict type-checked code.
fix
If you are using a type checker with strictness enabled, you might need to adjust your type annotations, e.g., using `Hist[Any]` instead of `Hist` for more flexible typing where the specific storage type is not known or needs to be generic.
affects: >=1.7.1
Errors
Common errors & fixes
TypeError: Not supported yet
Attempting to scale a slice of a histogram directly, which is not currently implemented in `boost-histogram`.
fix
Instead of direct scaling, retrieve the slice as a view, modify it, and then set the contents of the slice with the modified view. Alternatively, apply operations to the full histogram or use explicit loops.
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all().
This error typically occurred in older versions of `boost-histogram` when using `bh.numpy.histogram()` and supplying the `weights` argument as a NumPy array. This was a bug in the library's internal handling of the `weights` array's truthiness check.
fix
Upgrade to a newer version of `boost-histogram` (e.g., 1.0 or later), as this bug was fixed in subsequent releases.
TypeError: value() missing 1 required positional argument: 'index'
The `axis.value()` method requires an `index` argument to return the value at a specific bin index, but it was called without any arguments.
fix
Provide an integer index (or a sequence of indices) to the `value()` method, for example, `axis.value(0)` for the first bin, or use `axis.centers` or `axis.edges` to get arrays of bin centers or edges.
ValueError: There must be at least one bin in a category axis.
An attempt was made to create a `bh.axis.category` with an empty list of initial categories, even when `growth=True` was specified. While the axis can grow, it needs an initial set of bins.
fix
Initialize the `bh.axis.category` with at least one category, even if it's a placeholder, or ensure `growth=False` if an empty axis is genuinely intended (though an empty fixed-size category axis isn't very useful).
Upgrade
Version history
1.8.0latest on PyPI · released Aug 7, 2026
Audit
Dependencies
numpyrequiredUsed for efficient array operations, histogram views, and for multithreaded builds. Integrated for data input and output views.
Agent activity
22 hits · last 30 days
node
18
OpenAI (training)
1
Resources