mpmath icon indicating copy to clipboard operation
mpmath copied to clipboard

mpmath.mpf fails converting numpy.int64

Open i-am-b-soto opened this issue 5 years ago • 1 comments

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!

i-am-b-soto avatar Jun 01 '20 19:06 i-am-b-soto

@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.

skirpichev avatar Mar 14 '21 07:03 skirpichev

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 avatar Apr 15 '23 20:04 WarrenWeckesser

@WarrenWeckesser, this seems to be fixed in the current master, see #679 where a regression test was added. UPD: bisected to 0249d97.

skirpichev avatar Apr 16 '23 03:04 skirpichev

@skirpichev yes, it is fixed in the master branch. Thanks!

WarrenWeckesser avatar Apr 16 '23 09:04 WarrenWeckesser