Skip to content

Commit 00ff5b4

Browse files
authored
Save language restoration (#154)
* fix: resolve bug with python version in language loading via dill * ci: add newline
1 parent c1e624b commit 00ff5b4

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

pytoda/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
name = 'pytoda'
2-
__version__ = '1.0.1'
2+
__version__ = '1.0.2'

pytoda/proteins/protein_language.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,17 @@ def load(filepath: str) -> 'ProteinLanguage':
107107
Returns:
108108
ProteinLanguage: the loaded Protein language object.
109109
"""
110-
with open(filepath, 'rb') as f:
111-
protein_language = dill.load(f)
110+
try:
111+
with open(filepath, 'rb') as f:
112+
protein_language = dill.load(f)
113+
except TypeError:
114+
# Necessary to load python3.7 pickled objects with >=3.8
115+
# For details see: https://github.com/uqfoundation/dill/pull/406
116+
storage = dill._dill._reverse_typemap['CodeType']
117+
dill._dill._reverse_typemap['CodeType'] = dill._dill._create_code
118+
with open(filepath, 'rb') as f:
119+
protein_language = dill.load(f)
120+
dill._dill._reverse_typemap['CodeType'] = storage
112121
return protein_language
113122

114123
@staticmethod

pytoda/smiles/smiles_language.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,17 @@ def load(filepath: str) -> 'SMILESLanguage':
176176
warnings.warn(
177177
"Loading languages will use a text files in the future", FutureWarning
178178
)
179-
with open(filepath, 'rb') as f:
180-
smiles_language = dill.load(f)
179+
try:
180+
with open(filepath, 'rb') as f:
181+
smiles_language = dill.load(f)
182+
except TypeError:
183+
# Necessary to load python3.7 pickled objects with >=3.8:
184+
# For details see: https://github.com/uqfoundation/dill/pull/406
185+
storage = dill._dill._reverse_typemap['CodeType']
186+
dill._dill._reverse_typemap['CodeType'] = dill._dill._create_code
187+
with open(filepath, 'rb') as f:
188+
smiles_language = dill.load(f)
189+
dill._dill._reverse_typemap['CodeType'] = storage
181190
return smiles_language
182191

183192
@staticmethod

0 commit comments

Comments
 (0)