I'm trying to extend getitem of a simple list to allow string aliases for indices.
I'm aware that numba doesn't yet support strings. But I was hoping to somehow convert the python strings to integers using @lower_builtin:
@lower_builtin('getitem', types.List, types.Const)
def list_getitem(context, builder, sig, args):
# get content of const and turn into an integer
However the list_getitem doesn't seem to be called when using a string as index. If I use types.Integer it does get called ( when using an integer as index ).
I do get something similar to work with overload and a separate function:
def idx(s):
pass
@overload(idx)
def convert_str(s):
# logic to convert str to idx
@numba.njit
def test_idx():
lst = [0, 1, 2]
i = idx("a")
# works as expected/desired
return lst[i]
Any ideas?