From 4091e51a0a2bb21621eebca6d1ca111a5f30a101 Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Thu, 20 Sep 2018 10:56:52 -0500 Subject: [PATCH] fixes #2: numbers NameError and proper handling of weights scalar-to-array broadcasting --- uproot_methods/classes/TH1.py | 3 ++- uproot_methods/classes/TH2.py | 5 ++--- uproot_methods/version.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/uproot_methods/classes/TH1.py b/uproot_methods/classes/TH1.py index 66ce887..3deb3e2 100644 --- a/uproot_methods/classes/TH1.py +++ b/uproot_methods/classes/TH1.py @@ -28,6 +28,7 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import numbers import sys import numpy @@ -183,7 +184,7 @@ def fillallw(self, data, weights): data = numpy.array(data) if isinstance(weights, numbers.Real): - weights = numpy.empty_like(data) + weights = numpy.full(data.shape, weights) freq, edges = numpy.histogram(data, bins=numbins, range=(low, high), weights=weights, density=False) for i, x in enumerate(freq): diff --git a/uproot_methods/classes/TH2.py b/uproot_methods/classes/TH2.py index 0c9a0f9..282e537 100644 --- a/uproot_methods/classes/TH2.py +++ b/uproot_methods/classes/TH2.py @@ -28,6 +28,7 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import numbers import sys import numpy @@ -236,9 +237,7 @@ def fillallw(self, datax, datay, weights): datay = numpy.array(datay) if isinstance(weights, numbers.Real): - tmp_weight = weights - weights = numpy.empty_like(datax) - weights.fill(tmp_weight) # assign all elements of the array to the initial value + weights = numpy.full(datax.shape, weights) freq, xedges, yedges = numpy.histogram2d(datax, datay, diff --git a/uproot_methods/version.py b/uproot_methods/version.py index 0dbdb42..6979236 100644 --- a/uproot_methods/version.py +++ b/uproot_methods/version.py @@ -30,7 +30,7 @@ import re -__version__ = "0.0.8" +__version__ = "0.0.9" version = __version__ version_info = tuple(re.split(r"[-\.]", __version__))