Repository: nipy/nipype

Issue:
Propose removing "versioning" argument from loadpkl
The "versioning" argument to loadpkl no longer serves much purpose. I propose it be deleted. Thoughts?

https://github.com/nipy/nipype/blob/508df5e0531fb691b8b052e81a3bc03d1300d594/nipype/utils/filemanip.py#L678


Discussion:
cc @anibalsolon, as this was added in #2626.
Hi @stilley2 ! I am actually not aware of why it isn't required anymore. But if it is not, I am always happy with cutting off code.
Hi @anibalsolon , if my reading of the code is correct, the only thing it changes now is error reporting. loadpkl tries to read the version information regardless of if this flag is set, and if that fails it assumes it doesn't exist.
Yes @stilley2 so it can be removed indeed!

Resolving patch:
diff --git a/nipype/utils/filemanip.py b/nipype/utils/filemanip.py
--- a/nipype/utils/filemanip.py
+++ b/nipype/utils/filemanip.py
@@ -670,12 +670,12 @@ def load_json(filename):
 
 def loadcrash(infile, *args):
     if infile.endswith('pkl') or infile.endswith('pklz'):
-        return loadpkl(infile, versioning=True)
+        return loadpkl(infile)
     else:
         raise ValueError('Only pickled crashfiles are supported')
 
 
-def loadpkl(infile, versioning=False):
+def loadpkl(infile):
     """Load a zipped or plain cPickled file."""
     infile = Path(infile)
     fmlogger.debug('Loading pkl: %s', infile)
@@ -700,9 +700,6 @@ def loadpkl(infile, versioning=False):
             fmlogger.info('Successfully loaded pkl in compatibility mode.')
         # Unpickling problems
         except Exception as e:
-            if not versioning:
-                raise e
-
             if pkl_metadata and 'version' in pkl_metadata:
                 from nipype import __version__ as version
                 if pkl_metadata['version'] != version:


Test patch:
diff --git a/nipype/utils/tests/test_filemanip.py b/nipype/utils/tests/test_filemanip.py
--- a/nipype/utils/tests/test_filemanip.py
+++ b/nipype/utils/tests/test_filemanip.py
@@ -558,7 +558,7 @@ def test_versioned_pklization(tmpdir):
         with mock.patch('nipype.utils.tests.test_filemanip.Pickled', PickledBreaker), \
              mock.patch('nipype.__version__', '0.0.0'):
 
-            loadpkl('./pickled.pkz', versioning=True)
+            loadpkl('./pickled.pkz')
 
 
 def test_unversioned_pklization(tmpdir):
@@ -569,7 +569,7 @@ def test_unversioned_pklization(tmpdir):
 
     with pytest.raises(Exception):
         with mock.patch('nipype.utils.tests.test_filemanip.Pickled', PickledBreaker):
-            loadpkl('./pickled.pkz', versioning=True)
+            loadpkl('./pickled.pkz')
 
 
 def test_Path_strict_resolve(tmpdir):
@@ -589,11 +589,10 @@ def test_Path_strict_resolve(tmpdir):
     assert '%s/somefile.txt' % tmpdir == '%s' % testfile.resolve(strict=True)
 
 
-@pytest.mark.parametrize("load_versioning", [True, False])
 @pytest.mark.parametrize("save_versioning", [True, False])
-def test_pickle(tmp_path, save_versioning, load_versioning):
+def test_pickle(tmp_path, save_versioning):
     testobj = 'iamateststr'
     pickle_fname = str(tmp_path / 'testpickle.pklz')
     savepkl(pickle_fname, testobj, versioning=save_versioning)
-    outobj = loadpkl(pickle_fname, versioning=load_versioning)
+    outobj = loadpkl(pickle_fname)
     assert outobj == testobj