diff --git a/src/boost_histogram/_internal/hist.py b/src/boost_histogram/_internal/hist.py index 58a790f3..86d1d17e 100644 --- a/src/boost_histogram/_internal/hist.py +++ b/src/boost_histogram/_internal/hist.py @@ -98,11 +98,11 @@ def __init__(self, *axes, **kwargs): # Keyword only trick (change when Python2 is dropped) with KWArgs(kwargs) as k: - storage = k.optional("storage", Double()) + self._storage = k.optional("storage", Double()) # Check for missed parenthesis or incorrect types - if not isinstance(storage, Storage): - if issubclass(storage, Storage): + if not isinstance(self._storage, Storage): + if issubclass(self._storage, Storage): raise KeyError( "Passing in an initialized storage has been removed. Please add ()." ) @@ -119,8 +119,8 @@ def __init__(self, *axes, **kwargs): # Check all available histograms, and if the storage matches, return that one for h in _histograms: - if isinstance(storage, h._storage_type): - self._hist = h(axes, storage) + if isinstance(self._storage, h._storage_type): + self._hist = h(axes, self._storage) return raise TypeError("Unsupported storage") @@ -195,9 +195,14 @@ def fill(self, *args, **kwargs): threaded filling. Using 0 will automatically pick the number of available threads (usually two per core). """ - + # should not allow float weight for int storage + if "weight" in kwargs: + for w in kwargs["weight"]: + if not isinstance(self._storage._PyType, type(w)): + raise TypeError("Weight type must match storage type.") + threads = kwargs.pop("threads", None) - + if threads is None or threads == 1: self._hist.fill(*args, **kwargs) else: @@ -208,7 +213,7 @@ def fill(self, *args, **kwargs): self._hist._storage_type is _core.storage.mean or self._hist._storage_type is _core.storage.weighted_mean ): - raise RuntimeError("Mean histograms do not support threaded filling") + raise RuntimeError("Mean histograms do not support threaded filling.") weight = kwargs.pop("weight", None) sample = kwargs.pop("sample", None) diff --git a/src/boost_histogram/_internal/storage.py b/src/boost_histogram/_internal/storage.py index 8f1d22d3..f10388cc 100644 --- a/src/boost_histogram/_internal/storage.py +++ b/src/boost_histogram/_internal/storage.py @@ -17,6 +17,8 @@ def __repr__(self): @set_family(MAIN_FAMILY) @set_module("boost_histogram.storage") class Int64(store.int64, Storage): + def __init__(self): + self._PyType = int() pass @@ -29,6 +31,8 @@ class Double(store.double, Storage): @set_family(MAIN_FAMILY) @set_module("boost_histogram.storage") class AtomicInt64(store.atomic_int64, Storage): + def __init__(self): + self._PyType = int() pass