(@cython.cfunc + Type Annotation) Fragility
See original GitHub issueGoing through some of pandas’ cython modules to try to make code valid-python where possible, I’m seeing cythonize-time errors. It seems like some combinations are invalid for surprising reasons, e.g:
cpdef object get_rule_month(object source, object default='DEC')
# existing, works as expected
cpdef object get_rule_month(source: object, default: object='DEC'):
# seems OK
cpdef get_rule_month(source: object, default: object='DEC') -> object:
# breaks --> Syntax error in C variable declaration
@cython.ccall
def get_rule_month(source: object, default: object='DEC') -> object:
# breaks --> Exception clause not allowed for function returning Python object
@cython.ccall
def object get_rule_month(source: object, default: object='DEC'):
# breaks --> Expected '(', found 'get_rule_month'
@cython.ccall
@cython.returns(object)
def get_rule_month(source: object, default: object='DEC'):
# appears OK
Another example with a slightly different set of errors:
cdef inline bint is_null_datetime64(v):
# existing, OK
cdef inline is_null_datetime64(v) -> bint:
# breaks --> Syntax error in C variable declaration
@cython.cfunc
def inline is_null_datetime64(v) -> bint:
# breaks --> Expected '(', found 'is_null_datetime64
@cython.cfunc
@cython.inline
def is_null_datetime64(v) -> bint:
# breaks --> Function signature does not match previous declaration
This last one here is the one that is noticeably different from the first example.
Is this behavior intentional?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:16 (14 by maintainers)
Top Results From Across the Web
Pure Python Mode — Cython 3.0.0a11 documentation
This is accomplished via an augmenting .pxd file, via Python type PEP-484 type annotations (following PEP 484 and PEP 526), and/or via special...
Read more >10. Release Notes — Numba 0.39.0rc1+0.g26dde2b.dirty ...
The Numba dispatcher inspect_types() method now supports the kwarg pretty which if set to True will produce ANSI/HTML output, showing the annotated types, ......
Read more >Pure Python with Cython decorators: How to get attribute ...
@cython.cfunc decorator is an equivalent to cdef ing a function (see here for details), so this function is accessible only within C code....
Read more >numba Changelog - pyup.io
Numba's internal representations of Python/NumPy types are rendered inside GDB ... Fixes missing type annotation pass following #7704 (`stuartarchibald ...
Read more >University of Auckland Research Repository, ResearchSpace
described here has type annotations and constant declarations which are checked at ... The Cython implementation (Behnel et al., 2011) is an ahead-of-time ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m having the similar issues on cython V0.29 with return types in the .pyx file. Any python object return type breaks compilation in python compatible mode. Cython types work for returns (int, float, cython.int, cython.void, etc), np.ndarray and python builtins don’t.
Also returning None gives a different error:
which makes it not compatible with typed python even with just builtin types. If returning None is redundant, can cython just ignore it? or alias it to a cython void / NULL? (Should this be a separate issue?)
@Yobmod It looks like that there is a workaround for
-> object
case: If we add a decorator@cython.exceptval(check=False)
it works fine. The generated code still checks the return value for exceptions.