-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[BUG] Cannot write Int64 hist (with np.uint64 backend) to root file using uproot #526
Comments
Just as a side-comment about surprise: if an unsigned 64-bit integer needs to be extended to handle signed values, the only possible extension is floating point: >>> np.array([1, 2, 3], np.uint64) + np.array([1, 2, 3], np.int8)
array([2., 4., 6.]) (Floating point numbers are the only ones that cover the domain of large On the actual issue, the Uproot We could change Should this instead be an issue on boost-histogram about |
boost-histogram defines the different storage types here, and int64 is defined to use Indeed, despite conflicting documentation but in agreement with its name, Int64 hist-objects will happily accept negative integers: myh = hist.Hist.new.Regular(10, 0, 10).Int64()
myh[0] = -2 # works
assert(myh.values().dtype == np.int64) # True
assert(myh.values().dtype.type == np.int64) # False
assert(myh.values().dtype.type == np.long) # True So, there is no reason why storing Int64 histograms (hist/boost-histogram) into root files should not be possible, but uproot disagrees (because See also this numpy bug report. |
Conflicting docs probably came from the original start using uint. Only having 9223372036854775807 as a maximum instead of 18446744073709551615 isn't a bit deal, and it's nice to be able to support negative weights, histogram subtraction, etc. And it was needed to match NumPy. |
Describe the bug
It is not possible to write hist objects with
storage=hist.storage.Int64()
to root files using uprootSteps to reproduce
The following code reproduces the problem:
hist_double
is written as expected. root files can easily storeint64
histograms, however, the last line results in the following exception:ValueError: data to convert to TArray must have signed integer or floating-point type, not dtype('>i8')
The uproot
to_TArray
function looks it only supports writing signed integers, andhist.storage.Int64()
(surprisingly?) uses a np.uint64 backend forInt64()
. Is there a workaround to write hist objects to root files using uproot without conversion to Double?The text was updated successfully, but these errors were encountered: