random method incompatible with numpy.int64

Issue #39 closed
Pierre Denis repo owner created an issue

The random method raises an exception if the argument is a numpy.int64:

>>> from lea import *
>>> from numpy import int64
>>> tuples = list(zip(range(10), range(10, 20)))
>>> leagen = Lea.fromValFreqs(*tuples)
>>> leagen.random(10)
(0, 4, 4, 7, 5, 7, 2, 3, 9, 7)
>>> npint = int64(10)
>>> leagen.random(npint)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File
"/home/ali/.virtualenvs/unicity/lib/python3.5/site-packages/lea/lea.py",
line 1719, in random
     return tuple(islice(self.randomIter(),n))
ValueError: Stop argument for islice() must be None or an integer: 0 <= x <= sys.maxsize.

(reported by Ali Farzanehfar)

Comments (7)

  1. Pierre Denis reporter

    A possible workaround is to invoke Python's int function:

    >>> leagen.random(int(npint))
    

    The correction in Lea should update the random method to make this call on its argument.

  2. Log in to comment