Skip to content

Commit ce02a55

Browse files
committed
fix(interfaces): accept selection across lists of 1 element length
1 parent 69aca55 commit ce02a55

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

niworkflows/interfaces/utility.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
from nipype.interfaces.io import add_traits
1010
from nipype.interfaces.base import (
11-
traits, Str, DynamicTraitedSpec, BaseInterface, isdefined
11+
InputMultiObject, Str, DynamicTraitedSpec, BaseInterface, isdefined
1212
)
1313

1414

1515
class KeySelectInputSpec(DynamicTraitedSpec):
1616
key = Str(mandatory=True, desc='selective key')
17-
keys = traits.List(Str, mandatory=True, min=2, desc='index of keys')
17+
keys = InputMultiObject(Str, mandatory=True, min=1, desc='index of keys')
1818

1919

2020
class KeySelectOutputSpec(DynamicTraitedSpec):
@@ -75,6 +75,20 @@ class KeySelect(BaseInterface):
7575
Traceback (most recent call last):
7676
ValueError: Selected key "MNINLin2009cAsym" not found in the index
7777
78+
>>> ks = KeySelect(fields=['field1', 'field2', 'field3'])
79+
>>> ks.inputs.keys=['MNI152NLin6Asym']
80+
>>> ks.inputs.field1 = ['fsl']
81+
>>> ks.inputs.field2 = ['volume']
82+
>>> ks.inputs.field3 = [True]
83+
>>> ks.inputs.key = 'MNI152NLin6Asym'
84+
>>> ks.run().outputs
85+
<BLANKLINE>
86+
field1 = fsl
87+
field2 = volume
88+
field3 = True
89+
key = MNI152NLin6Asym
90+
<BLANKLINE>
91+
7892
"""
7993
input_spec = KeySelectInputSpec
8094
output_spec = KeySelectOutputSpec
@@ -120,7 +134,7 @@ def _check_len(self, name, new):
120134
raise ValueError('Selected key "%s" not found in the index' % new)
121135

122136
if name in self._fields:
123-
if isinstance(new, str) or len(new) <= 1:
137+
if isinstance(new, str) or len(new) < 1:
124138
raise ValueError('Trying to set an invalid value (%s) for input "%s"' % (
125139
new, name))
126140

0 commit comments

Comments
 (0)