Skip to content

Commit f066209

Browse files
Max BaakMax Baak
authored andcommitted
In sparselybin switch q array to floats before applying divide and floor
The same is done in binned histograms. If not, numpy throws TypeError on trivial integer array cases such as: >>> q = numpy.array([1,2,3,4]) >>> np.divide(q,1,q) >>> np.floor(q,q) which can easily happen if default binning is 1.
1 parent 675a297 commit f066209

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

histogrammar/primitives/sparselybin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,12 @@ def _numpy(self, data, weights, shape):
363363
subweights[selection] = 0.0
364364
self.nanflow._numpy(data, subweights, shape)
365365

366-
q = q.copy()
366+
# switch to float here like in bin.py else numpy throws
367+
# TypeError on trivial integer cases such as:
368+
# >>> q = numpy.array([1,2,3,4])
369+
# >>> np.divide(q,1,q)
370+
# >>> np.floor(q,q)
371+
q = numpy.array(q, dtype=numpy.float64)
367372
neginfs = numpy.isneginf(q)
368373
posinfs = numpy.isposinf(q)
369374

0 commit comments

Comments
 (0)