python 3.x - Dill failed to load back numpy arrays after loading back numpy record arrays -


all:

i'm trying save data in python program dill binary file. program used both regular numpy array , numpy record array. i'm having problem on loading regular numpy arrays if saved both numpy record arrays , regular arrays. problem can demonstrated following simple code:

import dill pickle import numpy np  class testdill:    def __init__(self, data):        self.data =data  # numpy record array type persontype = [('name', 'a32'), ('age', '<i2'), ('salary', '<i4'), ('weight','<f8')]    person = np.zeros(2, dtype=persontype, order='f') d = np.random.randn(5) d1 = testdill(d)  d = np.random.randn(5) d2 = testdill(d)  d = np.random.randn(5) d3 = testdill(d)   f= open('testdill.dat', 'wb') pickle.dump(person, f)  pickle.dump(d1, f) pickle.dump(d2, f) pickle.dump(d3, f)  f.close()  f= open('testdill.dat', 'rb')  person2 = pickle.load(f) d11 = pickle.load(f) d21 = pickle.load(f) d31 = pickle.load(f) 

the above code result key error on loading d11 object. don't know whether there bug in dill package or i'm not using dill correctly. appreciate suggestions , comments around problem. i'm using python 3.4 on 64-bit windows 7.

thanks,

john

i'm dill author. looks you've found bug. i'd appreciate if open issue on dill github page.

there workaround, , it's pickle structured array last. why work? um… don't know yet. (note: code simplified w/o changing test case)

import dill pickle import numpy np  class testdill(object):    def __init__(self, data):        self.data =data  persontype = [('name', 'a32'), ('age', '<i2')]    person = np.zeros(2, dtype=persontype, order='f') d = np.random.randn(5) d1 = testdill(d)  open('testdill.dat', 'wb') f:   pickle.dump(d1, f)   pickle.dump(person, f)   open('testdill.dat', 'rb') f:   d11 = pickle.load(f)   person2 = pickle.load(f) 

update: dill bug has been fixed. code works recent version on github.


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -