AttributeError: 'CppClassType' object has no attribute 'vtabptr_cname'
This is with 0.28.1. The CArrayData class is declared as follows:
cdef cppclass CArrayData" arrow::ArrayData":
shared_ptr[CDataType] type
int64_t length
int64_t null_count
int64_t offset
vector[shared_ptr[CBuffer]] buffers
vector[shared_ptr[CArrayData]] child_data
@staticmethod
shared_ptr[CArrayData] Make(const shared_ptr[CDataType]& type,
int64_t length,
const vector[shared_ptr[CBuffer]]& buffers,
int64_t null_count=-1,
int64_t offset=0)
When trying to compile the given code:
cdef class Array:
# [snip other methods]
@staticmethod
def from_buffers(DataType type, length, buffers, null_count=-1, offset=0):
cdef:
Buffer buf
vector[shared_ptr[CBuffer]] c_buffers
shared_ptr[CArrayData] ad
for buf in buffers:
c_buffers.push_back(buf.buffer)
ad = CArrayData.Make(type.sp_type, length, c_buffers, null_count, offset)
return pyarrow_wrap_array(MakeArray(ad))
Cython crashes with the following error:
Error compiling Cython file:
------------------------------------------------------------
...
vector[shared_ptr[CBuffer]] c_buffers
shared_ptr[CArrayData] ad
for buf in buffers:
c_buffers.push_back(buf.buffer)
ad = CArrayData.Make(type.sp_type, length, c_buffers, null_count, offset)
^
------------------------------------------------------------
/home/antoine/arrow/python/pyarrow/array.pxi:385:23: Compiler crash in AnalyseExpressionsTransform
ModuleNode.body = StatListNode(lib.pyx:22:0)
StatListNode.stats[51] = StatListNode(array.pxi:19:0)
StatListNode.stats[15] = CClassDefNode(array.pxi:273:5,
as_name = 'Array',
class_name = 'Array',
module_name = '',
visibility = 'private')
CClassDefNode.body = StatListNode(array.pxi:275:4)
StatListNode.stats[7] = CompilerDirectivesNode(array.pxi:377:4)
CompilerDirectivesNode.body = StatListNode(array.pxi:377:4)
StatListNode.stats[0] = DefNode(array.pxi:377:4,
is_staticmethod = True,
modifiers = [...]/0,
name = 'from_buffers',
np_args_idx = [...]/0,
num_required_args = 3,
py_wrapper_required = True,
reqd_kw_flags_cname = '0',
self_in_stararg = True,
used = True)
File 'Nodes.py', line 432, in analyse_expressions: StatListNode(array.pxi:378:8,
is_terminator = True)
File 'Nodes.py', line 432, in analyse_expressions: StatListNode(array.pxi:385:28)
File 'Nodes.py', line 5090, in analyse_expressions: SingleAssignmentNode(array.pxi:385:28)
File 'Nodes.py', line 5210, in analyse_types: SingleAssignmentNode(array.pxi:385:28)
File 'ExprNodes.py', line 5393, in analyse_types: SimpleCallNode(array.pxi:385:28,
analysed = True,
result_is_used = True,
use_managed_ref = True)
File 'ExprNodes.py', line 6732, in analyse_types: AttributeNode(array.pxi:385:23,
attribute = 'Make',
initialized_check = True,
is_attribute = 1,
is_called = 1,
needs_none_check = True,
result_is_used = True,
use_managed_ref = True)
File 'ExprNodes.py', line 6793, in analyse_as_type_attribute: AttributeNode(array.pxi:385:23,
attribute = 'Make',
initialized_check = True,
is_attribute = 1,
is_called = 1,
needs_none_check = True,
result_is_used = True,
use_managed_ref = True)
Compiler crash traceback from this point on:
File "/home/antoine/miniconda3/envs/pyarrow/lib/python3.6/site-packages/Cython/Compiler/ExprNodes.py", line 6793, in analyse_as_type_attribute
cname = "%s->%s" % (type.vtabptr_cname, entry.cname)
AttributeError: 'CppClassType' object has no attribute 'vtabptr_cname'
The crash disappears if I remove the default argument values, i.e. if I turn the method declaration to:
@staticmethod
shared_ptr[CArrayData] Make(const shared_ptr[CDataType]& type,
int64_t length,
const vector[shared_ptr[CBuffer]]& buffers,
int64_t null_count,
int64_t offset)
I bumped into this problem today as well. Here's a minimal reproducer, using the Cython magic for IPython:
In [1]: %load_ext cython
In [2]: %%cython -+
...: cdef extern from *:
...: cdef cppclass SomeClass:
...: @staticmethod
...: void func(int a, int b=0)
...:
...: SomeClass.func(1,2)
...:
...:
That results in:
Error compiling Cython file:
------------------------------------------------------------
...
cdef extern from *:
cdef cppclass SomeClass:
@staticmethod
void func(int a, int b=0)
SomeClass.func(1,2)
^
------------------------------------------------------------
.cache/ipython/cython/_cython_magic_c961a377a1670543c84a8818f0ec9563.pyx:6:9: Compiler crash in AnalyseExpressionsTransform
File 'Nodes.py', line 435, in analyse_expressions: StatListNode(_cython_magic_c961a377a1670543c84a8818f0ec9563.pyx:1:0)
File 'Nodes.py', line 5138, in analyse_expressions: ExprStatNode(_cython_magic_c961a377a1670543c84a8818f0ec9563.pyx:6:14)
File 'ExprNodes.py', line 587, in analyse_expressions: SimpleCallNode(_cython_magic_c961a377a1670543c84a8818f0ec9563.pyx:6:14,
analysed = True,
use_managed_ref = True)
File 'ExprNodes.py', line 5546, in analyse_types: SimpleCallNode(_cython_magic_c961a377a1670543c84a8818f0ec9563.pyx:6:14,
analysed = True,
use_managed_ref = True)
File 'ExprNodes.py', line 6881, in analyse_types: AttributeNode(_cython_magic_c961a377a1670543c84a8818f0ec9563.pyx:6:9,
attribute = 'func',
initialized_check = True,
is_attribute = 1,
is_called = 1,
needs_none_check = True,
result_is_used = True,
use_managed_ref = True)
File 'ExprNodes.py', line 6942, in analyse_as_type_attribute: AttributeNode(_cython_magic_c961a377a1670543c84a8818f0ec9563.pyx:6:9,
attribute = 'func',
initialized_check = True,
is_attribute = 1,
is_called = 1,
needs_none_check = True,
result_is_used = True,
use_managed_ref = True)
Compiler crash traceback from this point on:
File "/home/mwoznisk/.local/lib/python3.8/site-packages/Cython/Compiler/ExprNodes.py", line 6942, in analyse_as_type_attribute
cname = "%s->%s" % (type.vtabptr_cname, entry.cname)
AttributeError: 'CppClassType' object has no attribute 'vtabptr_cname'
Still reproduces with cython 3.0.2.
Still reproduces after the changes in #3235. Fortunately the workaround for this one is easy: remove default argument values; instead e.g. declare multiple overloads for the different parameter counts.