mverleg / pyjson_tricks

Extra features for Python's JSON: comments, order, numpy, pandas, datetimes, and many more! Simple but customizable.
Other
153 stars 23 forks source link

Compressed numpy arrays are decoded as writeable=False #90

Closed claydugo closed 1 year ago

claydugo commented 1 year ago

Reproduce:

import numpy as np
import json_tricks

data = np.zeros((2, 2))

data_uncompressed = json_tricks.dumps(data)
data_compressed = json_tricks.dumps(data, properties={'ndarray_compact': True})

reloaded_uncompressed = json_tricks.loads(data_uncompressed)
reloaded_compressed = json_tricks.loads(data_compressed)

assert np.array_equal(data, reloaded_uncompressed)
assert np.array_equal(data, reloaded_compressed)

assert reloaded_uncompressed.flags.writeable
assert reloaded_compressed.flags.writeable
Traceback (most recent call last):
  File "/tmp/reproduce.py", line 16, in <module>
    assert reloaded_compressed.flags.writeable
AssertionError

I also tried adding the 'ndarray_store_byteorder': 'suppress', flag to my dumps call but it does not change the outcome.

Can provide more information if there is something I am missing