Skip to content

Commit

Permalink
fix(traits): Replace deprecated traits.List$Sub with traits.List($Sub)
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Nov 18, 2024
1 parent ea4164c commit b713b4d
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 56 deletions.
3 changes: 2 additions & 1 deletion nipype/algorithms/rapidart.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ class ArtifactDetectInputSpec(BaseInterfaceInputSpec):
desc="Source of movement parameters",
mandatory=True,
)
use_differences = traits.ListBool(
use_differences = traits.List(
traits.Bool,
[True, False],
minlen=2,
maxlen=2,
Expand Down
2 changes: 0 additions & 2 deletions nipype/algorithms/tests/test_auto_ArtifactDetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ def test_ArtifactDetect_inputs():
xor=["norm_threshold"],
),
use_differences=dict(
maxlen=2,
minlen=2,
usedefault=True,
),
use_norm=dict(
Expand Down
3 changes: 2 additions & 1 deletion nipype/interfaces/ants/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,8 @@ class JointFusionInputSpec(ANTSCommandInputSpec):
usedefault=True,
desc=("Constrain solution to non-negative weights."),
)
patch_radius = traits.ListInt(
patch_radius = traits.List(
traits.Int,
minlen=3,
maxlen=3,
argstr="-p %s",
Expand Down
2 changes: 0 additions & 2 deletions nipype/interfaces/ants/tests/test_auto_JointFusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ def test_JointFusion_inputs():
),
patch_radius=dict(
argstr="-p %s",
maxlen=3,
minlen=3,
),
retain_atlas_voting_images=dict(
argstr="-f",
Expand Down
3 changes: 2 additions & 1 deletion nipype/interfaces/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
This module defines the API of all nipype interfaces.
"""
from traits.trait_handlers import TraitDictObject, TraitListObject
from traits.trait_dict_object import TraitDictObject
from traits.trait_list_object import TraitListObject
from traits.trait_errors import TraitError

from .core import (
Expand Down
3 changes: 2 additions & 1 deletion nipype/interfaces/base/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from packaging.version import Version

from traits.trait_errors import TraitError
from traits.trait_handlers import TraitDictObject, TraitListObject
from traits.trait_dict_object import TraitDictObject
from traits.trait_list_object import TraitListObject
from ...utils.filemanip import md5, hash_infile, hash_timestamp
from .traits_extension import (
traits,
Expand Down
11 changes: 6 additions & 5 deletions nipype/interfaces/dipy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os.path as op
import inspect
from functools import partial
import numpy as np
from ..base import (
traits,
Expand Down Expand Up @@ -109,15 +110,15 @@ def convert_to_traits_type(dipy_type, is_file=False):
dipy_type = dipy_type.lower()
is_mandatory = bool("optional" not in dipy_type)
if "variable" in dipy_type and "str" in dipy_type:
return traits.ListStr, is_mandatory
return partial(traits.List, traits.Str), is_mandatory
elif "variable" in dipy_type and "int" in dipy_type:
return traits.ListInt, is_mandatory
return partial(traits.List, traits.Int), is_mandatory
elif "variable" in dipy_type and "float" in dipy_type:
return traits.ListFloat, is_mandatory
return partial(traits.List, traits.Float), is_mandatory
elif "variable" in dipy_type and "bool" in dipy_type:
return traits.ListBool, is_mandatory
return partial(traits.List, traits.Bool), is_mandatory
elif "variable" in dipy_type and "complex" in dipy_type:
return traits.ListComplex, is_mandatory
return partial(traits.List, traits.Complex), is_mandatory
elif "str" in dipy_type and not is_file:
return traits.Str, is_mandatory
elif "str" in dipy_type and is_file:
Expand Down
51 changes: 27 additions & 24 deletions nipype/interfaces/dipy/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

def test_convert_to_traits_type():
Params = namedtuple("Params", "traits_type is_file")
Res = namedtuple("Res", "traits_type is_mandatory")
Res = namedtuple("Res", "traits_type subtype is_mandatory")
l_entries = [
Params("variable string", False),
Params("variable int", False),
Expand All @@ -42,35 +42,38 @@ def test_convert_to_traits_type():
Params("complex, optional", False),
]
l_expected = [
Res(traits.ListStr, True),
Res(traits.ListInt, True),
Res(traits.ListFloat, True),
Res(traits.ListBool, True),
Res(traits.ListComplex, True),
Res(traits.ListInt, False),
Res(traits.ListStr, False),
Res(traits.ListFloat, False),
Res(traits.ListBool, False),
Res(traits.ListComplex, False),
Res(traits.Str, True),
Res(traits.Int, True),
Res(File, True),
Res(traits.Float, True),
Res(traits.Bool, True),
Res(traits.Complex, True),
Res(traits.Str, False),
Res(traits.Int, False),
Res(File, False),
Res(traits.Float, False),
Res(traits.Bool, False),
Res(traits.Complex, False),
Res(traits.List, traits.Str, True),
Res(traits.List, traits.Int, True),
Res(traits.List, traits.Float, True),
Res(traits.List, traits.Bool, True),
Res(traits.List, traits.Complex, True),
Res(traits.List, traits.Int, False),
Res(traits.List, traits.Str, False),
Res(traits.List, traits.Float, False),
Res(traits.List, traits.Bool, False),
Res(traits.List, traits.Complex, False),
Res(traits.Str, None, True),
Res(traits.Int, None, True),
Res(File, None, True),
Res(traits.Float, None, True),
Res(traits.Bool, None, True),
Res(traits.Complex, None, True),
Res(traits.Str, None, False),
Res(traits.Int, None, False),
Res(File, None, False),
Res(traits.Float, None, False),
Res(traits.Bool, None, False),
Res(traits.Complex, None, False),
]

for entry, res in zip(l_entries, l_expected):
traits_type, is_mandatory = convert_to_traits_type(
entry.traits_type, entry.is_file
)
assert traits_type == res.traits_type
trait_instance = traits_type()
assert isinstance(trait_instance, res.traits_type)
if res.subtype:
assert isinstance(trait_instance.inner_traits()[0].trait_type, res.subtype)
assert is_mandatory == res.is_mandatory

with pytest.raises(IOError):
Expand Down
5 changes: 3 additions & 2 deletions nipype/interfaces/mrtrix3/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ class MRDeGibbsInputSpec(MRTrix3BaseInputSpec):
mandatory=True,
desc="input DWI image",
)
axes = traits.ListInt(
default_value=[0, 1],
axes = traits.List(
traits.Int,
[0, 1],
usedefault=True,
sep=",",
minlen=2,
Expand Down
2 changes: 0 additions & 2 deletions nipype/interfaces/mrtrix3/tests/test_auto_MRDeGibbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ def test_MRDeGibbs_inputs():
),
axes=dict(
argstr="-axes %s",
maxlen=2,
minlen=2,
sep=",",
usedefault=True,
),
Expand Down
15 changes: 10 additions & 5 deletions nipype/interfaces/spm/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ class ApplyVDMInputSpec(SPMCommandInputSpec):
desc="phase encode direction input data have been acquired with",
usedefault=True,
)
write_which = traits.ListInt(
write_which = traits.List(
traits.Int,
[2, 1],
field="roptions.which",
minlen=2,
Expand Down Expand Up @@ -524,7 +525,8 @@ class RealignInputSpec(SPMCommandInputSpec):
field="eoptions.wrap",
desc="Check if interpolation should wrap in [x,y,z]",
)
write_which = traits.ListInt(
write_which = traits.List(
traits.Int,
[2, 1],
field="roptions.which",
minlen=2,
Expand Down Expand Up @@ -731,7 +733,8 @@ class RealignUnwarpInputSpec(SPMCommandInputSpec):
"maximization and smoothness maximization of the estimated field."
),
)
est_reg_factor = traits.ListInt(
est_reg_factor = traits.List(
traits.Int,
[100000],
field="uweoptions.lambda",
minlen=1,
Expand Down Expand Up @@ -769,7 +772,8 @@ class RealignUnwarpInputSpec(SPMCommandInputSpec):
field="uweoptions.rem",
desc="Re-estimate movement parameters at each unwarping iteration.",
)
est_num_of_iterations = traits.ListInt(
est_num_of_iterations = traits.List(
traits.Int,
[5],
field="uweoptions.noi",
minlen=1,
Expand All @@ -783,7 +787,8 @@ class RealignUnwarpInputSpec(SPMCommandInputSpec):
usedefault=True,
desc="Point in position space to perform Taylor-expansion around.",
)
reslice_which = traits.ListInt(
reslice_which = traits.List(
traits.Int,
[2, 1],
field="uwroptions.uwwhich",
minlen=2,
Expand Down
2 changes: 0 additions & 2 deletions nipype/interfaces/spm/tests/test_auto_ApplyVDM.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ def test_ApplyVDM_inputs():
),
write_which=dict(
field="roptions.which",
maxlen=2,
minlen=2,
usedefault=True,
),
write_wrap=dict(
Expand Down
2 changes: 0 additions & 2 deletions nipype/interfaces/spm/tests/test_auto_Realign.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ def test_Realign_inputs():
),
write_which=dict(
field="roptions.which",
maxlen=2,
minlen=2,
usedefault=True,
),
write_wrap=dict(
Expand Down
6 changes: 0 additions & 6 deletions nipype/interfaces/spm/tests/test_auto_RealignUnwarp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@ def test_RealignUnwarp_inputs():
),
est_num_of_iterations=dict(
field="uweoptions.noi",
maxlen=1,
minlen=1,
usedefault=True,
),
est_re_est_mov_par=dict(
field="uweoptions.rem",
),
est_reg_factor=dict(
field="uweoptions.lambda",
maxlen=1,
minlen=1,
usedefault=True,
),
est_reg_order=dict(
Expand Down Expand Up @@ -80,8 +76,6 @@ def test_RealignUnwarp_inputs():
),
reslice_which=dict(
field="uwroptions.uwwhich",
maxlen=2,
minlen=2,
usedefault=True,
),
reslice_wrap=dict(
Expand Down

0 comments on commit b713b4d

Please sign in to comment.