Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TraitError: The 'file_name' trait of a PolyDataWriter instance must be a unicode string ... #2513

Closed
yarikoptic opened this issue Mar 26, 2018 · 3 comments · Fixed by #2511
Closed

Comments

@yarikoptic
Copy link
Member

Summary

trying to update debian package for 1.0.1-97-g803982c21 . not yet sure if that is nohow specifics of my system (will try now in a clean chroot etc) with python-traits 4.6.0-1+b1. Note that issue subject reflects only one of the two failures

=================================== FAILURES ===================================
_____________________________ test_ident_distances _____________________________
[gw3] linux2 -- Python 2.7.14 /usr/bin/python

tmpdir = local('/tmp/pytest-of-yoh/pytest-0/popen-gw3/test_ident_distances0')

    @pytest.mark.skipif(VTKInfo.no_tvtk(), reason="tvtk is not installed")
    def test_ident_distances(tmpdir):
        tmpdir.chdir()
    
        in_surf = example_data('surf01.vtk')
        dist_ident = m.ComputeMeshWarp()
        dist_ident.inputs.surface1 = in_surf
        dist_ident.inputs.surface2 = in_surf
>       dist_ident.inputs.out_file = tmpdir.join('distance.npy')

/home/yoh/deb/gits/pkg-exppsy/build-area/nipype-1.0.1+git97-g803982c21/nipype/algorithms/tests/test_mesh_ops.py:24: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/home/yoh/deb/gits/pkg-exppsy/build-area/nipype-1.0.1+git97-g803982c21/nipype/interfaces/base/traits_extension.py:103: in validate
    validated_value = super(File, self).validate(object, name, value)
/usr/lib/python2.7/dist-packages/traits/trait_types.py:411: in validate
    self.error( object, name, value )
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <nipype.interfaces.base.traits_extension.File object at 0x7f2809ce4110>
object = 
ignore_exception = False
metric = euclidean
out_file = distance.npy
out_warp .../nipype-1.0.1+git97-g803982c21/nipype/testing/data/surf01.vtk
weighting = none

name = 'out_file'
value = local('/tmp/pytest-of-yoh/pytest-0/popen-gw3/test_ident_distances0/distance.npy')

    def error ( self, object, name, value ):
        """Raises a TraitError exception.
    
            Parameters
            ----------
            object : object
                The object whose attribute is being assigned.
            name : str
                The name of the attribute being assigned.
            value : object
                The proposed new value for the attribute.
    
            Description
            -----------
            This method is called by the validate() method when an assigned value
            is not valid. Raising a TraitError exception either notifies the user of
            the problem, or, in the case of compound traits, provides a chance for
            another trait handler to handle to validate the value.
            """
        raise TraitError( object, name, self.full_info( object, name, value ),
>                         value )
E       TraitError: The 'out_file' trait of a ComputeMeshWarpInputSpec instance must be a file name, but a value of local('/tmp/pytest-of-yoh/pytest-0/popen-gw3/test_ident_distances0/distance.npy') <class 'py._path.local.LocalPath'> was specified.

/usr/lib/python2.7/dist-packages/traits/trait_handlers.py:172: TraitError
_____________________________ test_trans_distances _____________________________
[gw1] linux2 -- Python 2.7.14 /usr/bin/python

tmpdir = local('/tmp/pytest-of-yoh/pytest-0/popen-gw1/test_trans_distances0')

    @pytest.mark.skipif(VTKInfo.no_tvtk(), reason="tvtk is not installed")
    def test_trans_distances(tmpdir):
        from ...interfaces.vtkbase import tvtk
    
        in_surf = example_data('surf01.vtk')
        warped_surf = tmpdir.join('warped.vtk')
    
        inc = np.array([0.7, 0.3, -0.2])
    
        r1 = tvtk.PolyDataReader(file_name=in_surf)
        vtk1 = VTKInfo.vtk_output(r1)
        r1.update()
        vtk1.points = np.array(vtk1.points) + inc
    
>       writer = tvtk.PolyDataWriter(file_name=warped_surf)

/home/yoh/deb/gits/pkg-exppsy/build-area/nipype-1.0.1+git97-g803982c21/nipype/algorithms/tests/test_mesh_ops.py:47: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib/python2.7/dist-packages/tvtk/tvtk_classes.zip/tvtk_classes/poly_data_writer.py:46: in __init__
    tvtk_base.TVTKBase.__init__(self, vtk.vtkPolyDataWriter, obj, update, **traits)
/usr/lib/python2.7/dist-packages/tvtk/tvtk_base.py:336: in __init__
    super(TVTKBase, self).__init__(**traits)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <traits.trait_handlers.TraitCompound object at 0x7f32d813f890>
object = <tvtk.tvtk_classes.poly_data_writer.PolyDataWriter object at 0x7f32b66056b0>
name = 'file_name'
value = local('/tmp/pytest-of-yoh/pytest-0/popen-gw1/test_trans_distances0/warped.vtk')

    def error ( self, object, name, value ):
        """Raises a TraitError exception.
    
            Parameters
            ----------
            object : object
                The object whose attribute is being assigned.
            name : str
                The name of the attribute being assigned.
            value : object
                The proposed new value for the attribute.
    
            Description
            -----------
            This method is called by the validate() method when an assigned value
            is not valid. Raising a TraitError exception either notifies the user of
            the problem, or, in the case of compound traits, provides a chance for
            another trait handler to handle to validate the value.
            """
        raise TraitError( object, name, self.full_info( object, name, value ),
>                         value )
E       TraitError: The 'file_name' trait of a PolyDataWriter instance must be a unicode string or a value of type 'str' or None, but a value of local('/tmp/pytest-of-yoh/pytest-0/popen-gw1/test_trans_distances0/warped.vtk') <class 'py._path.local.LocalPath'> was specified.

/usr/lib/python2.7/dist-packages/traits/trait_handlers.py:172: TraitError

@djarecka
Copy link
Collaborator

we have traits >= 4.6, so would be good to see if this error still exists with 4.6

@effigies
Copy link
Member

effigies commented Mar 27, 2018

Ah, looks like this is a py.path issue. Can you change:

- writer = tvtk.PolyDataWriter(file_name=warped_surf)
+ writer = tvtk.PolyDataWriter(file_name=warped_surf.strpath)

A similar fix should apply for the other case, as well. It looks like we're not testing with tvtk on CircleCI...

@effigies
Copy link
Member

OTOH, it might be useful if future versions allow File traits to accept py.path and pathlib objects. There's been some relevant discussion in nipy/nibabel#610.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants