Skip to content

Running into TraitError on JSON load. #3536

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

Closed
TheChymera opened this issue Jan 27, 2023 · 4 comments
Closed

Running into TraitError on JSON load. #3536

TheChymera opened this issue Jan 27, 2023 · 4 comments

Comments

@TheChymera
Copy link
Collaborator

So after tackling the networkx issues there are still 20 errors left, and I'm trying to go through them one by one, but I'm already stuck on the first one :/ @effigies any idea what's up here?

[deco]~/src/nipype ❱ pytest -vvs nipype/interfaces/base/tests/test_core.py::test_BaseInterface_load_save_inputs
=========================================================== test session starts ============================================================
platform linux -- Python 3.10.9, pytest-7.2.1, pluggy-1.0.0 -- /usr/bin/python3.10
cachedir: .pytest_cache
rootdir: /home/chymera/src/nipype/nipype, configfile: pytest.ini
plugins: pkgcore-0.12.18, mock-3.10.0
collected 1 item

nipype/interfaces/base/tests/test_core.py::test_BaseInterface_load_save_inputs FAILED

================================================================= FAILURES =================================================================
___________________________________________________ test_BaseInterface_load_save_inputs ____________________________________________________

tmpdir = local('/tmp/pytest-of-chymera/pytest-1/test_BaseInterface_load_save_i0')

    def test_BaseInterface_load_save_inputs(tmpdir):
        tmp_json = tmpdir.join("settings.json").strpath

        class InputSpec(nib.TraitedSpec):
            input1 = nib.traits.Int()
            input2 = nib.traits.Float()
            input3 = nib.traits.Bool()
            input4 = nib.traits.Str()

        class DerivedInterface(nib.BaseInterface):
            input_spec = InputSpec

            def __init__(self, **inputs):
                super(DerivedInterface, self).__init__(**inputs)

        inputs_dict = {"input1": 12, "input3": True, "input4": "some string"}
        bif = DerivedInterface(**inputs_dict)
        bif.save_inputs_to_json(tmp_json)
        bif2 = DerivedInterface()
        bif2.load_inputs_from_json(tmp_json)
        assert bif2.inputs.get_traitsfree() == inputs_dict

        bif3 = DerivedInterface(from_file=tmp_json)
        assert bif3.inputs.get_traitsfree() == inputs_dict

        inputs_dict2 = inputs_dict.copy()
        inputs_dict2.update({"input4": "some other string"})
        bif4 = DerivedInterface(from_file=tmp_json, input4=inputs_dict2["input4"])
        assert bif4.inputs.get_traitsfree() == inputs_dict2

        bif5 = DerivedInterface(input4=inputs_dict2["input4"])
        bif5.load_inputs_from_json(tmp_json, overwrite=False)
        assert bif5.inputs.get_traitsfree() == inputs_dict2

        bif6 = DerivedInterface(input4=inputs_dict2["input4"])
        bif6.load_inputs_from_json(tmp_json)
        assert bif6.inputs.get_traitsfree() == inputs_dict

        # test get hashval in a complex interface
        from nipype.interfaces.ants import Registration

        settings = example_data(example_data("smri_ants_registration_settings.json"))
        with open(settings) as setf:
            data_dict = json.load(setf)

        tsthash = Registration()
>       tsthash.load_inputs_from_json(settings)

nipype/interfaces/base/tests/test_core.py:153:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
nipype/interfaces/base/core.py:489: in load_inputs_from_json
    setattr(self.inputs, key, inputs_dict[key])
/usr/lib/python3.10/site-packages/traits/trait_types.py:2695: in validate
    return TraitListObject(self, object, name, value)
/usr/lib/python3.10/site-packages/traits/trait_list_object.py:584: in __init__
    super().__init__(
/usr/lib/python3.10/site-packages/traits/trait_list_object.py:213: in __init__
    super().__init__(self.item_validator(item) for item in iterable)
/usr/lib/python3.10/site-packages/traits/trait_list_object.py:213: in <genexpr>
    super().__init__(self.item_validator(item) for item in iterable)
/usr/lib/python3.10/site-packages/traits/trait_list_object.py:867: in _item_validator
    return trait_validator(object, self.name, value)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <traits.trait_handlers.TraitCompound object at 0x7ff90dcbc520>
object =
args = <undefined>
collapse_output_transforms = True
convergence_threshold = [1e-06]
convergence_window_size = [10]
d... True]
verbose = False
winsorize_lower_quantile = 0.0
winsorize_upper_quantile = 1.0
write_composite_transform = False

name = 'transform_parameters', value = [0.1]

    def error(self, object, name, value):
        """Raises a TraitError exception.

        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.

        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.
        """
>       raise TraitError(
            object, name, self.full_info(object, name, value), value
        )
E       traits.trait_errors.TraitError: Each element of the 'transform_parameters' trait of a RegistrationInputSpec instance must be a tuple of the form: (a float) or a tuple of the form: (a float, a float, a float) or a tuple of the form: (a float, an integer, an integer, an integer) or a tuple of the form: (a float, an integer, a float, a float, a float, a float) or a tuple of the form: (a float, a float, a float, an integer) or a tuple of the form: (a float, an integer, an integer, an integer, an integer), but a value of [0.1] <class 'list'> was specified.

/usr/lib/python3.10/site-packages/traits/base_trait_handler.py:74: TraitError
@effigies
Copy link
Member

What version of traits do you have?

@TheChymera
Copy link
Collaborator Author

@effigies using =traits-6.4.1

@effigies
Copy link
Member

Traits 6.4 broke a lot of things; we require traits<6.4. There are no plans to overhaul nipype 1 to use traits 6.4+.

@TheChymera
Copy link
Collaborator Author

That was indeed it. Thank you.

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

No branches or pull requests

2 participants