NumpyJSONDecoder
Hello,
I see you have an extended class of JSONEncoder that allows saving into JSON types not supported by this class. However, I can't seem to find the reverse class, allowing you to recover these types from json. Is it not implemented, or did I just not find it?
Thanks in advance, Diogo Valada
Hi @Astlaan
Unfortunately that is generally not possible. The numpy encoder works by converting numpy arrays into python lists since json only has one list type it is not really possible to distinguish between a python list and a numpy array when you load this back into memory
Couldn't this simply be done by encoding numpy/python lists in the same fashion as numbers.Complex/UFloat? I.e with a dictionary specifying the type?
It could still have backwards compatibility by decoding the arrays encoded the current way as python lists by default, since they can then easily be turned into numpy arrays with np.array() (which is what a user would have to do manually anyway).
Or we can just decode it always as python lists while sticking with the current encoding scheme.
@jenshnielsen thank you for the replies and support!!
Quick questions before developing any solution:
Would a PR for a two-way conversion that would preserve python types be accepted?
Possibly with a configurable behavior for numpy to preserve backwards compatibility?
Would a PR for a two-way conversion that would preserve python types be accepted?
of course, we can have a look! but a thorough testing would be warranted :)
Possibly with a configurable behavior for numpy to preserve backwards compatibility?
if that's feasible, yes! :)