Skip to content

Commit 52818ea

Browse files
committed
FIX: loadpkl failed when pklz file contained versioning info
loadpkl called pickle.load at file position 0, which would fail if the first line of the file was json versioning info (as when using savepkl with versioning=True). This was fixed by only seeking to position 0 if no versioning information is found.
1 parent 508df5e commit 52818ea

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

nipype/tests/test_utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from nipype import utils
2+
3+
4+
def test_pickle(tmp_path):
5+
testobj = 'iamateststr'
6+
pickle_fname = str(tmp_path / 'testpickle.pklz')
7+
utils.filemanip.savepkl(pickle_fname, testobj)
8+
outobj = utils.filemanip.loadpkl(pickle_fname)
9+
assert outobj == testobj
10+
11+
12+
def test_pickle_versioning(tmp_path):
13+
testobj = 'iamateststr'
14+
pickle_fname = str(tmp_path / 'testpickle.pklz')
15+
utils.filemanip.savepkl(pickle_fname, testobj, versioning=True)
16+
outobj = utils.filemanip.loadpkl(pickle_fname)
17+
assert outobj == testobj

nipype/utils/filemanip.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,6 @@ def loadpkl(infile, versioning=False):
689689
pkl_metadata_line = pkl_file.readline()
690690
pkl_metadata = json.loads(pkl_metadata_line)
691691
except (UnicodeDecodeError, json.JSONDecodeError):
692-
pass
693-
finally:
694692
# Could not get version info
695693
pkl_file.seek(0)
696694

0 commit comments

Comments
 (0)