Pickles in python 3
When writing a pickle file in python 3, it is necessary to open the file in "wb" mode (instead of "w"). For example, when I run:
from chemicalchecker.core import ChemicalChecker
cc = ChemicalChecker()
s3 = cc.get_signature('sign3', 'reference', 'B4.001')
p3 = cc.get_signature('proj3', 'reference', 'B4.001', proj_type='PCA')
p3.fit(s3)
p3.plot()
I get the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-50c49b599e0b> in <module>
5 s3 = cc.get_signature('sign3', 'reference', 'B4.001')
6 p3 = cc.get_signature('proj3', 'reference', 'B4.001', proj_type='PCA')
----> 7 p3.fit(s3)
8 p3.plot()
/aloy/home/mduran/myscripts/chemical_checker/package/chemicalchecker/core/proj.py in fit(self, signature, validations, *args, **kwargs)
39 def fit(self, signature, validations=True, *args, **kwargs):
40 """Take an input learn a 2D representation."""
---> 41 self.projector.fit(signature, validations, *args, **kwargs)
42
43 def predict(self, signature, destination, *args, **kwargs):
/aloy/home/mduran/myscripts/chemical_checker/package/chemicalchecker/core/projector/pca.py in fit(self, signature, validations, chunk_size)
74 self.__log.info("Projecting took %s" % t_delta)
75 # save model
---> 76 pickle.dump(self.algo, open(self.algo_path, 'w'))
77 # save h5
78 sdtype = DataSignature.string_dtype()
TypeError: write() argument must be str, not bytes