Numba: How to avoid <type 'reflected list' found for argument> warning?

Viewed 3098

In a numba function, I was passing the arguments like this:

sets_one_step(idx,sets=[set1, set2], indexes=[sort_idx1, sort_idx2], probs=[P1, P2])

After running the code I got the following warning:

/.local/lib/python3.6/site-packages/numba/core/ir_utils.py:2031: NumbaPendingDeprecationWarning: 
Encountered the use of a type that is scheduled for deprecation: type 'reflected list' found for argument 'sets' of function '__numba_parfor_gufunc_0x7f5ebfb88748'.

this particular error/warning may have originated from the following line inside the function:

for k in prange(len(sets)):

Here, set1, set2 are numpy arrays (integer or flaot32). If this was only 2 sets, then I could make them individual arguments in function. However, I can have more than 2 such arrays for my application. I would like to know how to avoid this warning in future for my use case.

1 Answers

Consider the following code:

import numba as nb

@nb.njit
def process_some_list(lst):
    return lst[0]

Passing a standard Python list produces the following output:

>>> process_some_list([1,2,3])
.../numba/core/ir_utils.py:2119: NumbaPendingDeprecationWarning: 
Encountered the use of a type that is scheduled for deprecation:
type 'reflected list' found for argument 'lst' of function 'process_some_list'.
For more information visit https://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-reflection-for-list-and-set-types
[... more lines deleted ...]
1

The result is correct, but Numba says that reflected list is scheduled for deprecation. According to the docs you can use a typed.List, as in this example:

>>> process_some_list(nb.typed.List([1,2,3]))
1

However, if you need a list of sets:

>>> lst = [{1, 2}, {3, 4}]
>>> process_some_list(nb.typed.List(lst))

You get the same deprecation message for Set:

.../numba/typed/typedlist.py:83: NumbaPendingDeprecationWarning: 
Encountered the use of a type that is scheduled for deprecation: type 'reflected set' found for argument 'item' of function 'impl_append.<locals>.impl'.
For more information visit https://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-reflection-for-list-and-set-types
[... more lines deleted ...]
{1, 2}

The result is again correct, but the docs say typed.Set is not yet implemented, so you may need to live with the warnings. They only appear when the function is compiled, either during the first execution, or upon declaration when using signatures for the parameters and return type.

Related