Deep copy of typed lists

Hi,
I’ve run into an issue when trying to deep copy typed lists. I wasn’t sure if it’s a bug or something to be expected.

import copy
import numpy as np
from numba.typed import List as NumbaList

numba_list = NumbaList()
numba_list.append(np.array([1, 2, 3]))
numba_list_dc = copy.deepcopy(numba_list)

I get the following traceback:

Traceback (most recent call last):
  File "numba_test.py", line 11, in <module>
    numba_list_dc = copy.deepcopy(numba_list)
  File "C:\User\Python38\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\User\Python38\lib\copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\User\Python38\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\User\Python38\lib\copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\User\Python38\lib\copy.py", line 161, in deepcopy
    rv = reductor(4)
TypeError: cannot pickle '_nrt_python._MemInfo' object

Another issue has had a similar error.
My current idea is to manually perform the deep copy by copying the non-basic types in my original list. I’d appreciate any tips.

I think you’ve guessed correctly, that this is a bug stemming from the issue that you linked to. I think your manual deep copy is the best workaround for now.

1 Like