mpmath
mpmath copied to clipboard
mpmath.mpf fails converting numpy.int64
Hi!
I understand there was a very similar issue #382 that is closed, but it appears I'm getting the same issue again.
>>from mpmath import mpf
>>import numpy
>>my_mpf = mpf(numpy.int64(1))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "...site-packages/mpmath/ctx_mp_python.py", line 77, in __new__
v._mpf_ = mpf_pos(cls.mpf_convert_arg(val, prec, rounding), prec, rounding)
File "...site-packages/mpmath/ctx_mp_python.py", line 96, in mpf_convert_arg
raise TypeError("cannot create mpf from " + repr(x))
TypeError: cannot create mpf from 1
To my understanding, I'm using the latest version of mpmath
>> import mpmath
>> mpmath.__version__
1.1.0
python --version 3.7.6
Thanks!
@fredrik-johansson, I think the #382 wasn't fixed by #412. Merged pr even doesn't have a regression test. Probably, that issue must be reopened and the current - closed.
This is still an issue in version 1.3.0.
A work-around is to use mp.mathify:
In [19]: import numpy as np
In [20]: from mpmath import mp
In [21]: mp.mpmathify(np.int64(123))
Out[21]: mpf('123.0')
@WarrenWeckesser, this seems to be fixed in the current master, see #679 where a regression test was added. UPD: bisected to 0249d97.
@skirpichev yes, it is fixed in the master branch. Thanks!