I also thought the error throws, because the sum is applied over an empty array. sum function uses an iteration method to get a result and it can't be iterated over an empty array.
However, the histogram may contain random values, other than zero, so this could be at random, first time works, another time not. But when a value overflows the allowed range for an int64 number, an error could be also thrown.
Getting myself such an error, I had tried to convert values using the int() function, or float() in my case, and all Runtime Warnings disappeared. These function are acting like a cast function, that limits the values to the accepted range.
You can also convert the values in the for loop, at the cost of an extra function call. Another possibility would be to check the valid value in a try statement (although there would be several extra statements) and if a NaN value it will be encountered, you could use a continue statement.