1

What is the proper way to include a list of strings in a Numba jitclass? The documentation here is very limited and I am currently encountering DeprecationWarnings.

Should I use an array of strings instead?

For example:

import numpy as np
from numba.experimental import jitclass
from numba import types


spec = [
    ('datetime', types.NPDatetime('s')),
    ('strings', types.List(types.unicode_type)),
]
@jitclass(spec)
class DateTimeStringClass:
    def __init__(self, datetime, strings):
        self.datetime = datetime
        self.strings = strings

# Example usage
datetime_obj = np.datetime64('2024-03-02 02:00:00')
string_list = ['string1', '323', 'string3']
obj = DateTimeStringClass(datetime_obj, string_list)
<string>:3: NumbaPendingDeprecationWarning: 
Encountered the use of a type that is scheduled for deprecation: type 'reflected list' found for argument 'strings' of function 'DateTimeStringClass.__init__'.

For more information visit https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-reflection-for-list-and-set-types

File "<stdin>", line 3:
<source missing, REPL/exec in use?>

C:\numba\core\ir_utils.py:2172: NumbaPendingDeprecationWarning: 
Encountered the use of a type that is scheduled for deprecation: type 'reflected list' found for argument 'strings' of function 'ctor'.

For more information visit https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-reflection-for-list-and-set-types

File "<string>", line 2:
<source missing, REPL/exec in use?>

  warnings.warn(NumbaPendingDeprecationWarning(msg, loc=loc))
1
  • 1
    Numba does not support reflected lists and will not (because it is dynamic and heterogeneous which is also inefficient). You need typed lists instead. Lists are less efficient than arrays but arrays of strings are meant to contain strings of approximately equal size. If the size of the strings is very variable, then lists are better. Note that Numba is not meant for string computation in the first place and so it is not optimized for that either (actually pretty slow in practice). Commented Mar 3, 2024 at 2:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.