Skip to content

Commit e98181b

Browse files
committed
fix AddCSVRow when using infields
1 parent 0d3bbdc commit e98181b

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

nipype/algorithms/misc.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from ..interfaces.base import (BaseInterface, traits, TraitedSpec, File,
3535
InputMultiPath, OutputMultiPath,
3636
BaseInterfaceInputSpec, isdefined,
37-
DynamicTraitedSpec)
37+
DynamicTraitedSpec, Undefined)
3838
from nipype.utils.filemanip import fname_presuffix, split_filename
3939
iflogger = logging.getLogger('interface')
4040

@@ -785,7 +785,8 @@ def _list_outputs(self):
785785

786786

787787
class AddCSVRowInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec):
788-
in_file = traits.File(mandatory=True, desc='Input comma-separated value (CSV) files')
788+
in_file = traits.File(mandatory=True,
789+
desc='Input comma-separated value (CSV) files')
789790
_outputs = traits.Dict(traits.Any, value={}, usedefault=True)
790791

791792
def __setattr__(self, key, value):
@@ -804,13 +805,15 @@ class AddCSVRowOutputSpec(TraitedSpec):
804805

805806

806807
class AddCSVRow(BaseInterface):
808+
807809
"""Simple interface to add an extra row to a csv file
808810
809811
.. note:: Requires `pandas <http://pandas.pydata.org/>`_
810812
811813
.. warning:: Multi-platform thread-safe execution is possible with
812-
`lockfile <https://pythonhosted.org/lockfile/lockfile.html>`_. Please recall that (1)
813-
this module is alpha software; and (2) it should be installed for thread-safe writing.
814+
`lockfile <https://pythonhosted.org/lockfile/lockfile.html>`_. Please
815+
recall that (1) this module is alpha software; and (2) it should be
816+
installed for thread-safe writing.
814817
If lockfile is not installed, then the interface is not thread-safe.
815818
816819
@@ -850,22 +853,26 @@ def _run_interface(self, runtime):
850853
try:
851854
import pandas as pd
852855
except ImportError:
853-
raise ImportError('This interface requires pandas (http://pandas.pydata.org/) to run.')
856+
raise ImportError(('This interface requires pandas '
857+
'(http://pandas.pydata.org/) to run.'))
854858

855859
try:
856860
import lockfile as pl
857861
self._have_lock = True
858862
except ImportError:
859-
import warnings
860-
warnings.warn(('Python module lockfile was not found: AddCSVRow will not be thread-safe '
861-
'in multi-processor execution'))
863+
from warnings import warn
864+
warn(('Python module lockfile was not found: AddCSVRow will not be'
865+
' thread-safe in multi-processor execution'))
862866

863867
input_dict = {}
864868
for key, val in self.inputs._outputs.items():
865869
# expand lists to several columns
870+
if key == 'trait_added' and val in self.inputs._outputs.keys():
871+
continue
872+
866873
if isinstance(val, list):
867-
for i,v in enumerate(val):
868-
input_dict['%s_%d' % (key,i)]=v
874+
for i, v in enumerate(val):
875+
input_dict['%s_%d' % (key, i)] = v
869876
else:
870877
input_dict[key] = val
871878

0 commit comments

Comments
 (0)