Skip to content

DataGrabber.run() fails with TypeError when only one file matches template #3732

@Poisson14

Description

@Poisson14

Summary

When using DataGrabber from Nipype with only one file matching the template path, DataGrabber.run() raises:

TypeError: 'in <string>' requires string as left operand, not NoneType

If two or more files match the template path, it works as intended.

Actual behavior

With a single match to the template path, dg.run() fails with the above TypeError.

Expected behavior

If there is only one file matching the template, it should return the single file path in the outputs without error, consistent with the behavior when multiple files match.

How to replicate the behavior

A minimal dataset is provided here: NipypeTest.zip.

Failing case: one file matches

from nipype.interfaces.io import DataGrabber

dg = DataGrabber()
dg.inputs.sort_filelist = True
dg.inputs.template = "/path/to/NipypeTest/*/MyFile-A.nii.gz"
dg.run()

Error output:

Traceback (most recent call last):
  File "<python-input-20>", line 1, in <module>
    dg.run()
  File ".../nipype/interfaces/base/core.py", line 404, in run
    outputs = self.aggregate_outputs(runtime)
  File ".../nipype/interfaces/base/core.py", line 433, in aggregate_outputs
    predicted_outputs = self._list_outputs()
  File ".../nipype/interfaces/io.py", line 1300, in _list_outputs
    if None in outputs[key]:
TypeError: 'in <string>' requires string as left operand, not NoneType

Working case: two files match

from nipype.interfaces.io import DataGrabber

dg = DataGrabber()
dg.inputs.sort_filelist = True
dg.inputs.template = "/path/to/NipypeTest/*/MyFile-*.nii.gz"
dg.run()
# <nipype.interfaces.base.support.InterfaceResult object ...>

Execution environment

  • Python: 3.12.5
  • Nipype: 1.10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions