Skip to content

Commit

Permalink
Save language restoration (#154)
Browse files Browse the repository at this point in the history
* fix: resolve bug with python version in language loading via dill

* ci: add newline
  • Loading branch information
jannisborn authored Apr 16, 2022
1 parent c1e624b commit 00ff5b4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pytoda/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name = 'pytoda'
__version__ = '1.0.1'
__version__ = '1.0.2'
13 changes: 11 additions & 2 deletions pytoda/proteins/protein_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,17 @@ def load(filepath: str) -> 'ProteinLanguage':
Returns:
ProteinLanguage: the loaded Protein language object.
"""
with open(filepath, 'rb') as f:
protein_language = dill.load(f)
try:
with open(filepath, 'rb') as f:
protein_language = dill.load(f)
except TypeError:
# Necessary to load python3.7 pickled objects with >=3.8
# For details see: https://github.com/uqfoundation/dill/pull/406
storage = dill._dill._reverse_typemap['CodeType']
dill._dill._reverse_typemap['CodeType'] = dill._dill._create_code
with open(filepath, 'rb') as f:
protein_language = dill.load(f)
dill._dill._reverse_typemap['CodeType'] = storage
return protein_language

@staticmethod
Expand Down
13 changes: 11 additions & 2 deletions pytoda/smiles/smiles_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,17 @@ def load(filepath: str) -> 'SMILESLanguage':
warnings.warn(
"Loading languages will use a text files in the future", FutureWarning
)
with open(filepath, 'rb') as f:
smiles_language = dill.load(f)
try:
with open(filepath, 'rb') as f:
smiles_language = dill.load(f)
except TypeError:
# Necessary to load python3.7 pickled objects with >=3.8:
# For details see: https://github.com/uqfoundation/dill/pull/406
storage = dill._dill._reverse_typemap['CodeType']
dill._dill._reverse_typemap['CodeType'] = dill._dill._create_code
with open(filepath, 'rb') as f:
smiles_language = dill.load(f)
dill._dill._reverse_typemap['CodeType'] = storage
return smiles_language

@staticmethod
Expand Down

0 comments on commit 00ff5b4

Please sign in to comment.