[pypy-issue] Issue #2874: numpy.frombuffer(ffi.buffer(x)) fails with the official numpy module. (pypy/pypy)
HexDecimal
issues-reply at bitbucket.org
Tue Aug 21 23:20:35 EDT 2018
New issue 2874: numpy.frombuffer(ffi.buffer(x)) fails with the official numpy module.
https://bitbucket.org/pypy/pypy/issues/2874/numpyfrombuffer-ffibuffer-x-fails-with-the
HexDecimal:
This is valid CPython code, it also works on PyPy with the pypy/numpy fork:
```python
import cffi, numpy
ffi = cffi.FFI()
c_array = ffi.new('int[4]')
buf = ffi.buffer(c_array)
np_array = numpy.frombuffer(buf, numpy.intc)
print(np_array)
```
But when run on PyPy with the official numpy module you'll get this error:
```
Traceback (most recent call last):
File "test.py", line 5, in <module>
np_array = numpy.frombuffer(buf, numpy.intc)
AttributeError: '_cffi_backend.buffer' object has no attribute '__buffer__'
```
I can work around the error on PyPy3 by wrapping `buf` in a `memoryview` but that breaks Python2.
More information about the pypy-issue
mailing list