[Numpy-discussion] Changes in PyArray_FromAny between 1.5.x and 1.6.x

Dag Sverre Seljebotn d.s.seljebotn@astro.uio...
Mon Jun 4 16:12:44 CDT 2012


On 06/04/2012 09:06 PM, Mike Hansen wrote:
> On Mon, May 28, 2012 at 3:15 AM, Mike Hansen<mhansen@gmail.com>  wrote:
>> In trying to upgrade NumPy within Sage, we notices some differences in
>> behavior between 1.5 and 1.6.  In particular, in 1.5, we have
>>
>> sage: f = 0.5
>> sage: f.__array_interface__
>> {'typestr': '=f8'}
>> sage: numpy.array(f)
>> array(0.5)
>> sage: numpy.array(float(f))
>> array(0.5)
>>
>> In 1.6, we get the following,
>>
>> sage: f = 0.5
>> sage: f.__array_interface__
>> {'typestr': '=f8'}
>> sage: numpy.array(f)
>> array(0.500000000000000, dtype=object)
>>
>> This seems to be do to the changes in PyArray_FromAny introduced in
>> https://github.com/mwhansen/numpy/commit/2635398db3f26529ce2aaea4028a8118844f3c48
>> .  In particular, _array_find_type used to be used to query our
>> __array_interface__ attribute, and it no longer seems to work.  Is
>> there a way to get the old behavior with the current code?

No idea. If you want to spend the time to fix this properly, you could 
implement PEP 3118 and use that instead to export your array data (which 
can be done from Cython using __getbuffer__ on a Cython class).

Dag


More information about the NumPy-Discussion mailing list