Closed
Description
The new feature of reading settings from a json file (#1591) has introduced/uncovered the following issue derived from encoding when hashing inputs:
from nipype.interfaces.ants import Registration
tsthash = Registration(from_file='examples/smri_ants_registration_settings.json')
tsthash.inputs.get_hashval(hash_method='timestamp')
This leads (py27, at the very least) to:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-12-ed85d387f813> in <module>()
----> 1 tsthash.inputs.get_hashval(hash_method='timestamp')
/home/oesteban/workspace/nipype/nipype/interfaces/base.pyc in get_hashval(self, hash_method)
574 self._get_sorteddict(val, True, hash_method=hash_method,
575 hash_files=hash_files)))
--> 576 return dict_withhash, md5(encode_dict(dict_nofilename).encode()).hexdigest()
577
578 def _get_sorteddict(self, object, dictwithhash=False, hash_method=None,
/home/oesteban/workspace/nipype/nipype/utils/filemanip.pyc in encode_dict(value)
105 if i > 0:
106 retval += ', '
--> 107 retval += encode_dict(v)
108 return retval + ']'
109 return repr(value)
/home/oesteban/workspace/nipype/nipype/utils/filemanip.pyc in encode_dict(value)
97 if isinstance(value, tuple):
98 val0 = encode_dict(value[0])
---> 99 val1 = encode_dict(value[1])
100 return '(' + val0 + ', ' + val1 + ')'
101
/home/oesteban/workspace/nipype/nipype/utils/filemanip.pyc in encode_dict(value)
105 if i > 0:
106 retval += ', '
--> 107 retval += encode_dict(v)
108 return retval + ']'
109 return repr(value)
/home/oesteban/workspace/nipype/nipype/utils/filemanip.pyc in encode_dict(value)
97 if isinstance(value, tuple):
98 val0 = encode_dict(value[0])
---> 99 val1 = encode_dict(value[1])
100 return '(' + val0 + ', ' + val1 + ')'
101
IndexError: tuple index out of range
I'm already working on the patch.
If the from_file
feature is not used everything will work fine.