I am trying to add a second function to the example at (
https://arrow.apache.org/docs/python/integration/extending.html), and am
getting a compilation error message.  I can't tell if I'm trying to access
ValueOrDie() improperly or if I might be missing a modification to setup.py
from the example.

The function is as follows:

def print_array(obj):
    # Just an example function accessing both the pyarrow Cython API
    # and the Arrow C++ API
    cdef shared_ptr[CArray] arr = pyarrow_unwrap_array(obj)
    if arr.get() == NULL:
        raise TypeError("not an array")
    cdef arr_len =  arr.get().length()
    cdef int i
    cdef CResult[shared_ptr[CScalar]] r
    for i in range(arr_len):
        r = arr.get().GetScalar(i)
        if r.ok():
            print(i, r.ValueOrDie())

And produces an error on compilation:

Error compiling Cython file:
------------------------------------------------------------
...
    cdef int i
    cdef CResult[shared_ptr[CScalar]] r
    for i in range(arr_len):
        r = arr.get().GetScalar(i)
        if r.ok():
            print(i, r.ValueOrDie())
                     ^
------------------------------------------------------------

example.pyx:26:22: Object of type 'CResult[shared_ptr[CScalar]]' has no
attribute 'ValueOrDie'
Traceback (most recent call last):
  File "/home/ubuntu/repos/LbdInternal/PyarrowCython/setup.py", line 12, in
<module>
    ext_modules = cythonize("example.pyx")
  File
"/home/ubuntu/miniconda3/envs/lbdenv/lib/python3.10/site-packages/Cython/Build/Dependencies.py",
line 1127, in cythonize
    cythonize_one(*args)
  File
"/home/ubuntu/miniconda3/envs/lbdenv/lib/python3.10/site-packages/Cython/Build/Dependencies.py",
line 1250, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: example.pyx

Environment is as follows:

Ubuntu 20.04/x86
Python 3.10.4
cython 0.29.30
pyarrow 8.0.0

Any help would be appreciated.

Thanks,
Cedric

Reply via email to