0

I encountered a strange error while attempting to count the list of tuples. Any leads or alternate solution is appreciated.

please copy the total_bp_counts list from this text file

https://drive.google.com/file/d/1mTR78PC2ml0LqYkyT-N1QwyQb7Z9Ab0r/view

# Replace the below total_bp_counts line with content from text file 
########################
total_bp_counts = list()
######################## 

bp_count_dict = dict()

bp_counter = 0
for bp, bp_count in total_bp_counts:
    bp_counter += bp_count
    if bp in bp_count_dict:
        bp_count_dict[bp] += bp_count
    else:
        bp_count_dict[bp] = bp_count

print(bp_counter)
print(bp_count_dict)



RuntimeWarning: overflow encountered in byte_scalars
  bp_count_dict[bp] += bp_count
56768
{('A', 'U'): -52, ('A', 'C'): 0, ('A', 'G'): 0, ('U', 'C'): 0, ('U', 'G'): 111, ('C', 'G'): -123}

Process finished with exit code 0

Its strange that while the total summation of of numericals is 56768, overflow happens in dictionary.

Additional Details:

Python Version: 3.7.7, Architecture: 64bit, Windows 10
hello world
  • 660
  • 2
  • 6
  • 25
  • I cannot reproduce this. The output for me is ``56768`` ``{('A', 'U'): 19916, ('A', 'C'): 0, ('A', 'G'): 0, ('U', 'C'): 0, ('U', 'G'): 4719, ('C', 'G'): 32133}`` without any error. What Python implementation, version and build are you running this with? – MisterMiyagi Sep 22 '20 at 13:55
  • It works for me. No overflow. What OS are you using? Which version of python? – Mike67 Sep 22 '20 at 13:55
  • @MisterMiyagi , Here are the details Python Version: 3.7.7, Architecture: 64bit, Windows 10 – hello world Sep 22 '20 at 14:17
  • @Mike67 Here are the details Python Version: 3.7.7, Architecture: 64bit, Windows 10 – hello world Sep 22 '20 at 14:20
  • In your script, add `print(sys.maxsize)`. This will show the maximum integer value allowed. – Mike67 Sep 22 '20 at 14:32
  • Its 9223372036854775807 – hello world Sep 22 '20 at 14:35
  • @Mike67 ``sys.maxsize`` is not the maximum integer size. It is the maximum for the internal ``Py_ssize_t`` and container sizes, not the ``int``/``long`` type. ``sys.maxsize + 1`` is a well-defined, non-infinite number. – MisterMiyagi Sep 22 '20 at 14:37
  • Update: I am able to get the result without any issue in a standalone script with the above code. But the code snippet shared is the part of another program where overflow is noticed. – hello world Sep 22 '20 at 14:41
  • 2
    Similar https://stackoverflow.com/questions/7559595/python-runtimewarning-overflow-encountered-in-long-scalars are you using numpy? – snakecharmerb Sep 22 '20 at 14:41
  • @snakecharmerb you are right. Noticed that the integer in the data points Ex: (('A', 'U'), 10)) is of type numpy; The data is actually generated from the another function.. . – hello world Sep 22 '20 at 14:54
  • changed from count_matrix = np.zeros(shape=(x, y), dtype=np.int8) to count_matrix = np.zeros(shape=(x, y), dtype=np.int64). This fixed the issue. Thanks a lot guys. Might seem simple, but you save my debugging time. – hello world Sep 22 '20 at 15:07

0 Answers0