I'm not entirely sure of the details of this because I haven't ever really encountered a read-only array before, but the this script should explain the issue:
import numpy as np
import msgpack
import msgpack_numpy
from msgpack_numpy import patch
patch()
x = np.array([(1, 2, b'a', [1.0, 2.0])],
np.dtype([('arg0', np.uint32),
('arg1', np.uint32),
('arg2', 'S1'),
('arg3', np.float32, (2,))]))
x['arg0'] = [2]
x['arg0'] == [2]
x_enc = msgpack.packb(x)
x2 = msgpack.unpackb(x_enc)
# ValueError here
try:
x2['arg0'] = [1]
except ValueError:
# I guess this is expected?
x3 = np.array(x2)
x3['arg0'] = [1]
Does this mean the user is expected to make a copy of any decoded array they wish to modify?
Yes. The numpy.frombuffer() function used to recreate the encoded array returns a read-only array. I just added a note to the README regarding this for the edification of other users.
I'm not entirely sure of the details of this because I haven't ever really encountered a read-only array before, but the this script should explain the issue:
Does this mean the user is expected to make a copy of any decoded array they wish to modify?