Skip to content

Problem with strings being converted to unicode #2038

@polosecki

Description

@polosecki

Summary

Regular strings seem to be incorrectly converted into unicode (for the Function utility interface at least). This causes functions to fail. Error seems more general than just the Function utiliy interface.

Actual behavior

Strings get converted to unicode. This causes functions that expect regular strings to fail
The code below for instance, produces the following error:

File "test.py", line 9, in
from nipype.interfaces.utility import Function
File "/home/opt/anaconda2/lib/python2.7/site-packages/nipype/init.py", line 49, in
from .pipeline import Node, MapNode, JoinNode, Workflow
File "/home/opt/anaconda2/lib/python2.7/site-packages/nipype/pipeline/init.py", line 10, in
from .engine import Node, MapNode, JoinNode, Workflow
File "/home/opt/anaconda2/lib/python2.7/site-packages/nipype/pipeline/engine/init.py", line 12, in
from .workflows import Workflow
File "/home/opt/anaconda2/lib/python2.7/site-packages/nipype/pipeline/engine/workflows.py", line 22, in
standard_library.install_aliases()
File "/home/opt/anaconda2/lib/python2.7/site-packages/future/standard_library/init.py", line 483, in install_aliases
import test
File "/home/polo/test.py", line 21, in
save_txt.run()
File "/home/opt/anaconda2/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1081, in run
runtime = self._run_wrapper(runtime)
File "/home/opt/anaconda2/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1029, in _run_wrapper
runtime = self._run_interface(runtime)
File "/home/opt/anaconda2/lib/python2.7/site-packages/nipype/interfaces/utility/wrappers.py", line 194, in _run_interface
out = function_handle(**args)
File "", line 4, in save_txt
File "/home/opt/anaconda2/lib/python2.7/site-packages/numpy/lib/npyio.py", line 1143, in savetxt
raise ValueError('invalid fmt: %r' % (fmt,))
ValueError: invalid fmt: u'%.6f'
Interface Function failed to run.

Expected behavior

Regular strings should remain regular strings?

How to replicate the behavior

This is the code that reproduces the error:

from nipype.interfaces.utility import Function

def save_txt(out_file):
    import numpy as np
    this_array = np.array(['1.1'])
    np.savetxt(out_file, this_array, fmt='%.6f')
    return out_file

save_txt = Function(function=save_txt, input_names='out_file',
                    output_names='out_file')

save_txt.inputs.out_file = 'test.txt'
save_txt.run()

Also the following code seem to reproduce the same or related error:
print(nipype.get_info())

Script/Workflow details

None

Platform details:

Please paste the output of: python -c "import nipype; print(nipype.get_info()); print(nipype.__version__)"

I can't run nipype.get_info() !! I get an InterpolationSyntaxError caused also by convertion of string into unicode again!! My nipype.version is u'0.13.0' (notice the Unicode)

Execution environment

'2.7.13 |Anaconda custom (64-bit)| (default, Dec 20 2016, 23:09:15)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]'

Choose one

  • My python environment outside container (Not sure what this part means)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions